React Native ios:应用程序在发送到后台时崩溃
Posted
技术标签:
【中文标题】React Native ios:应用程序在发送到后台时崩溃【英文标题】:React Native ios: App crashes when it sent to the background 【发布时间】:2017-03-22 11:24:35 【问题描述】:我有一个 React Native ios 应用程序。我正在尝试解决一个问题,但我还无法解决它。
当我通过按两次主页按钮将应用程序发送到后台时,或者当我传递到另一个应用程序时,应用程序崩溃。你可以看下面的视频;
You can see error image with this link
http://sendvid.com/gwoqfybp
错误:
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)
解决方案
基本上是由 Google Analytics 插件引起的问题。我切换到 Fribase Analytics 并解决了问题!
【问题讨论】:
【参考方案1】:您需要更改应用程序状态并确保没有进程正在运行,例如不会在后台运行的推送通知。尝试发布正在运行的代码,我将尝试更改我的答案。
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
【讨论】:
@ilker 另外,在手机上试用一下,看看它是如何在后台运行的。有些东西在模拟器中无法正常工作。 我正在使用 REDUX 和 REDUX-PERSIST,所以当 AppState 更改为“非活动”或更改为“再次活动”以防止崩溃时,我应该对存储/状态进行任何处理吗? @ilker 您必须确保在应用程序处于后台时停止触摸通知等进程,否则它将崩溃。这是我能给的最好的建议。 @Ilker 欢迎您,抱歉,我无法提供更多帮助。也许您可以发布应用程序崩溃时发生的代码。以上是关于React Native ios:应用程序在发送到后台时崩溃的主要内容,如果未能解决你的问题,请参考以下文章
为啥我不能在 iOS 上离开键盘以在 React Native App 中发送帖子?
React-Native - 将应用程序发送到 iPhone 进行测试的最佳方式
在 expo/react-native 中发送图像时随机出现“错误处理请求正文”