我有一个React Native ios应用程序。我正试图解决一个问题,但我还是无法解决。
当我通过按两次主页按钮或每次传递到另一个应用程序将应用程序发送到后台时,应用程序崩溃。您可以在下面看到视频;
You can see error image with this link
错误:
2016-11-08 20:51:58.874 NewsApp[33572:686315] -[RCTDeviceExtension orientationDidChange:]: unrecognized selector sent to instance 0x60000001d100
2016-11-08 20:51:58.884 NewsApp[33572:686315] WARNING: GoogleAnalytics 3.15 void GAIUncaughtExceptionHandler(NSException *) (GAIUncaughtExceptionHandler.m:48): Uncaught exception: -[RCTDeviceExtension orientationDidChange:]: unrecognized selector sent to instance 0x60000001d100
2016-11-08 20:51:59.018 NewsApp[33572:686315] invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
2016-11-08 20:51:59.961503 NewsApp[33572:689959] [] __nw_connection_get_connected_socket_block_invoke 210 Connection has no connected handler
2016-11-08 20:52:03.298381 NewsApp[33572:689437] [] __nw_connection_get_connected_socket_block_invoke 211 Connection has no connected handler
2016-11-08 20:52:04.005 NewsApp[33572:686315] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RCTDeviceExtension orientationDidChange:]: unrecognized selector sent to instance 0x60000001d100'
*** First throw call stack:
(
0 CoreFoundation 0x000000010789f34b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000106ccb21e objc_exception_throw + 48
2 CoreFoundation 0x000000010790ef34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000107824c15 ___forwarding___ + 1013
4 CoreFoundation 0x0000000107824798 _CF_forwarding_prep_0 + 120
5 CoreFoundation 0x000000010783d19c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
6 CoreFoundation 0x000000010783d09b _CFXRegistrationPost + 427
7 CoreFoundation 0x000000010783ce02 ___CFXNotificationPost_block_invoke + 50
8 CoreFoundation 0x00000001077ffea2 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 2018
9 CoreFoundation 0x00000001077fef3b _CFXNotificationPost + 667
10 Foundation 0x00000001067930ab -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
11 UIKit 0x0000000108d24e3e -[UIApplication _stopDeactivatingForReason:] + 633
12 UIKit 0x0000000108d2c712 __62-[UIApplication _sceneSettingsPostLifecycleEventDiffInspector]_block_invoke.1251 + 107
13 FrontBoardServices 0x000000010bc1a7f5 __52-[FBSSettingsDiffInspector inspectDiff:withContext:]_block_invoke.27 + 231
14 Foundation 0x00000001067f7199 __NSIndexSetEnumerate + 1027
15 BaseBoard 0x000000010be05acb -[BSSettingsDiff inspectChangesWithBlock:] + 116
16 FrontBoardServices 0x000000010bc14354 -[FBSSettingsDiff inspectOtherChangesWithBlock:] + 92
17 FrontBoardServices 0x000000010bc1a598 -[FBSSettingsDiffInspector inspectDiff:withContext:] + 332
18 UIKit 0x0000000108d2d1a8 __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke + 201
19 UIKit 0x0000000108d2cdea -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:] + 1060
20 UIKit 0x0000000109258676 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:] + 492
21 FrontBoardServices 0x000000010bc0302e __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.376 + 204
22 FrontBoardServices 0x000000010bc31723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
23 FrontBoardServices 0x000000010bc3159c -[FBSSerialQueue _performNext] + 189
24 FrontBoardServices 0x000000010bc31925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
25 CoreFoundation 0x0000000107844311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
26 CoreFoundation 0x000000010782959c __CFRunLoopDoSources0 + 556
27 CoreFoundation 0x0000000107828a86 __CFRunLoopRun + 918
28 CoreFoundation 0x0000000107828494 CFRunLoopRunSpecific + 420
29 GraphicsServices 0x000000010b819a6f GSEventRunModal + 161
30 UIKit 0x0000000108d2f964 UIApplicationMain + 159
31 NewsApp 0x0000000102822dcf main + 111
32 libdyld.dylib 0x000000010a70668d start + 1
33 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
答案 0 :(得分:0)
您需要更改应用状态并确保没有正在运行的进程,例如不会在后台运行的推送通知。尝试发布正在运行的代码,我会尝试更改我的答案。
getInitialState: function() {
return {
currentAppState: AppState.currentState,
};
},
componentDidMount: function() {
AppState.addEventListener('change', this._handleAppStateChange);
},
componentWillUnmount: function() {
AppState.removeEventListener('change', this._handleAppStateChange);
},
_handleAppStateChange: function(currentAppState) {
this.setState({ currentAppState, });
},
render: function() {
return (
<Text>Current state is: {this.state.currentAppState}</Text>
);
},
请阅读此处以获取完整示例和文档 https://facebook.github.io/react-native/docs/appstate.html