我是IOS开发的新手,我已经为IOS开发并构建了一个应用程序。 React Native中的Android应用程序在Android中完全正常运行。我还在iPhone模拟器上安装了应用程序进行测试,在应用程序打开后成功构建,然后崩溃,Xcode显示错误堆栈。
堆栈跟踪
2018-03-26 17:18:59.537548+0530 VwWoocommerceAppMain[57934:681649] -[__NSDictionaryM length]: unrecognized selector sent to instance 0x60000023abc0
2018-03-26 17:18:59.555 [fatal][tid:com.facebook.react.AsyncLocalStorageQueue] Exception '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x60000023abc0' was thrown while invoking multiSet on target AsyncLocalStorage with params (
(
(
cart,
{
}
)
),
5873
)
callstack: (
0 CoreFoundation 0x0000000103f8212b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102874f41 objc_exception_throw + 48
2 CoreFoundation 0x0000000104003024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000103f04f78 ___forwarding___ + 1432
4 CoreFoundation 0x0000000103f04958 _CF_forwarding_prep_0 + 120
5 VwWoocommerceAppMain 0x0000000101956824 -[RCTAsyncLocalStorage _writeEntry:changedManifest:] + 258
6 VwWoocommerceAppMain 0x0000000101957104 -[RCTAsyncLocalStorage multiSet:callback:] + 436
7 CoreFoundation 0x0000000103f0636c __invoking___ + 140
8 CoreFoundation 0x0000000103f06240 -[NSInvocation invoke] + 320
9 CoreFoundation 0x0000000103f1ec26 -[NSInvocation invokeWithTarget:] + 54
10 VwWoocommerceAppMain 0x0000000101966929 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 602
11 VwWoocommerceAppMain 0x00000001019ac7a8 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 266
12 VwWoocommerceAppMain 0x00000001019ac522 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 78
13 libdispatch.dylib 0x0000000108bf32f7 _dispatch_call_block_and_release + 12
14 libdispatch.dylib 0x0000000108bf433d _dispatch_client_callout + 8
15 libdispatch.dylib 0x0000000108bfc855 _dispatch_queue_serial_drain + 1162
16 libdispatch.dylib 0x0000000108bfd1ea _dispatch_queue_invoke + 336
17 libdispatch.dylib 0x0000000108bf8f7c _dispatch_queue_override_invoke + 733
18 libdispatch.dylib 0x0000000108c00102 _dispatch_root_queue_drain + 772
19 libdispatch.dylib 0x0000000108bffda0 _dispatch_worker_thread3 + 132
20 libsystem_pthread.dylib 0x00000001091465a2 _pthread_wqthread + 1299
21 libsystem_pthread.dylib 0x000000010914607d start_wqthread + 13
)
2018-03-26 17:18:59.558030+0530 VwWoocommerceAppMain[57934:681649] Exception '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x60000023abc0' was thrown while invoking multiSet on target AsyncLocalStorage with params (
(
(
cart,
{
}
)
),
5873
)
callstack: (
0 CoreFoundation 0x0000000103f8212b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102874f41 objc_exception_throw + 48
2 CoreFoundation 0x0000000104003024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000103f04f78 ___forwarding___ + 1432
4 CoreFoundation 0x0000000103f04958 _CF_forwarding_prep_0 + 120
5 VwWoocommerceAppMain 0x0000000101956824 -[RCTAsyncLocalStorage _writeEntry:changedManifest:] + 258
6 VwWoocommerceAppMain 0x0000000101957104 -[RCTAsyncLocalStorage multiSet:callback:] + 436
7 CoreFoundation 0x0000000103f0636c __invoking___ + 140
8 CoreFoundation 0x0000000103f06240 -[NSInvocation invoke] + 320
9 CoreFoundation 0x0000000103f1ec26 -[NSInvocation invokeWithTarget:] + 54
10 VwWoocommerceAppMain 0x0000000101966929 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 602
11 VwWoocommerceAppMain 0x00000001019ac7a8 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 266
12 VwWoocommerceAppMain 0x00000001019ac522 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 78
13 libdispatch.dylib 0x0000000108bf32f7 _dispatch_call_block_and_release + 12
14 libdispatch.dylib 0x0000000108bf433d _dispatch_client_callout + 8
15 libdispatch.dylib 0x0000000108bfc855 _dispatch_queue_serial_drain + 1162
16 libdispatch.dylib 0x0000000108bfd1ea _dispatch_queue_invoke + 336
17 libdispatch.dylib 0x0000000108bf8f7c _dispatch_queue_override_invoke + 733
18 libdispatch.dylib 0x0000000108c00102 _dispatch_root_queue_drain + 772
19 libdispatch.dylib 0x0000000108bffda0 _dispatch_worker_thread3 + 132
20 libsystem_pthread.dylib 0x00000001091465a2 _pthread_wqthread + 1299
21 libsystem_pthread.dylib 0x000000010914607d start_wqthread + 13
)
2018-03-26 17:18:59.561965+0530 VwWoocommerceAppMain[57934:681649] *** Terminating app due to uncaught exception 'RCTFatalException: Exception '-[__NSDictionaryM length]: unrecognized selector sent to instance 0x60000023abc0' was thrown while invoking multiSet on target AsyncLocalStorage with params (
(
(
cart,
{
}
)
),
5873
)
callstack: (
0 CoreFoundation 0x0000000103f8212b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102874f41 objc_exception_throw + 48
2 CoreFoundation 0x0000000104003024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000103f04f78 ___forwarding___ + 1432
4 CoreFoundation 0x0000000103f04958 _CF_forwarding_prep_0 + 120
5 VwWoocommerceAppMain 0x0000000101956824 -[RCTAsyncLocalStorage _writeEntry:changedManifest:] + 258
6 VwWoocommerceAppMain 0x0000000101957104 -[RCTAsyncLocalStorage multiSet:callback:] + 436
7 CoreFoundation 0x0000000103f0636c __invoking___ + 140
8 CoreFoundation 0x0000000103f06240 -[NSInvocation invoke] + 320
9 CoreFoundation 0x0000000103f1ec26 -[NSInvocation invokeWithTarget:] + 54
10 VwWoocommerceAppMain 0x0000000101966929 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 602
11 VwWoocommerceAppMain 0x00000001019ac7a8 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 266
12 VwWoocommerceAppMain 0x00000001019ac522 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 78
13 libdispatch.dylib 0x0000000108bf32f7 _dispatch_call_block_and_release + 12
14 libdispatch.dylib 0x0000000108bf433d _dispatch_client_callout + 8
15 libdispatch.dylib 0x0000000108bfc855 _dispatch_queue_serial_drain + 1162
16 libdispatch.dylib 0x0000000108bfd1ea _dispatch_queue_invoke + 336
17 libdispatch.dylib 0x0000000108bf8f7c _dispatch_queue_override_invoke + 733
18 libdispatch.dylib 0x0000000108c00102 _dispatch_root_queue_drain + 772
19 libdispatch.dylib 0x0000000108bffda0 _dispatch_worker_thread3 + 132
20 libsystem_pthread.dylib 0x00000001091465a2 _pthread_wqthread + 1299
21 libsystem_pthread.dylib 0x000000010914607d start_wqthread + 13
)', reason: 'Exception '-[__NSDictionaryM length]: unrecognized selector sent to instanc...'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103f8212b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000102874f41 objc_exception_throw + 48
2 VwWoocommerceAppMain 0x0000000101953a22 RCTFormatError + 0
3 VwWoocommerceAppMain 0x00000001019ac9bc _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicE + 798
4 VwWoocommerceAppMain 0x00000001019ac522 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 78
5 libdispatch.dylib 0x0000000108bf32f7 _dispatch_call_block_and_release + 12
6 libdispatch.dylib 0x0000000108bf433d _dispatch_client_callout + 8
7 libdispatch.dylib 0x0000000108bfc855 _dispatch_queue_serial_drain + 1162
8 libdispatch.dylib 0x0000000108bfd1ea _dispatch_queue_invoke + 336
9 libdispatch.dylib 0x0000000108bf8f7c _dispatch_queue_override_invoke + 733
10 libdispatch.dylib 0x0000000108c00102 _dispatch_root_queue_drain + 772
11 libdispatch.dylib 0x0000000108bffda0 _dispatch_worker_thread3 + 132
12 libsystem_pthread.dylib 0x00000001091465a2 _pthread_wqthread + 1299
13 libsystem_pthread.dylib 0x000000010914607d start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
如果有人知道请帮助。
答案 0 :(得分:2)
对于IOS,您需要在inittailize上输入一个空对象。
可以使用下面的代码来解决:
AsyncStorage.setItem('@key', JSON.stringify({}))
答案 1 :(得分:1)
请避免在ios的异步存储中出现空对象,这将解决您的问题
答案 2 :(得分:1)
在AsyncStorage
中保存数据时,无论您使用什么数据,始终使用JSON.stringify
:
AsyncStorage.setItem('@key', 'will work on Android'))
AsyncStorage.setItem('@key', JSON.stringify('will work on both iOS and Android'))
答案 3 :(得分:0)
我遇到了同样的问题。问题是iOS在可变字典上寻找名为length()的函数,但NSDictionaryM使用count()。解决方法是对对象进行字符串化,使其不使用可变字典。
Android代码工作正常,对象存储并且没有指向错误函数的函数指针。
在我的项目中,我试图使用asyncstorage持久保存会话密钥。我有一个叫做存储的包装器。我也是新人,所以我可能不会在这里做最好的做法。
import {storage, keys} from './storage';
storage.store(keys.session, res.data).then(()=>{}).catch(()=>{}); //Will crash in iOS, but work fine in Android
storage.store(keys.session, JSON.stringify(res.data)).then(()=>{}).catch(()=>{}); //Will work fine on both.
以下是完整的方法:
getSession(email, password){
Network.login(email, password)
.then((res) => {
if(res.code == 1){
storage.store(keys.session, JSON.stringify(res.data)).then(()=>{
//Hurray
}).catch((error)=>{
throw new Error(error);
});
store.dispatch({
type: actions.SESSION,
session: res.data
});
return res.data;
}else{
throw new Error(res.data);
}
})
.catch((err) => {
this.setState({error: err.message});
});
}
答案 4 :(得分:0)
我的问题是 MapboxGL tileUrlTemplates
是一个内部为 false 的数组。
在 Android 上运行时错误消息要好得多,只是一个提示。