[ https://issues.apache.org/jira/browse/CB-1578?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13470266#comment-13470266 ]
Christoph Jerolimov commented on CB-1578: ----------------------------------------- Thank you, but i think it's not necessary to add these code also to the CDVConnection and CDVLocalStorage plugin because the dealloc of the parent class CDVPlugin was called automatically. > App crash (while stopping) caused by an unregistered notification handler in > CDVConnection > ------------------------------------------------------------------------------------------ > > Key: CB-1578 > URL: https://issues.apache.org/jira/browse/CB-1578 > Project: Apache Cordova > Issue Type: Bug > Components: iOS > Affects Versions: 2.0.0, 2.1.0 > Environment: iOS, all versions > XCode, all versions > Reporter: Christoph Jerolimov > Assignee: Becky Gibson > Priority: Critical > > The class {{CDVConnection}} registered itself as observer for background > events {{UIApplicationDidEnterBackgroundNotification}} and > {{UIApplicationWillEnterForegroundNotification}}. But it did NOT unregistered > these calls, for example in the dealloc method. > This caused in different type of errors which all ends in an app crash. If a > CDVConnection instance was already removed from the memory the selectors > onPause and onResume will be called on random other objects which doesn't > support this selector (1) or illegal memory access! > {code} > # Only an example, this error calls selectors on "random memory / objects"! > <Error>: -[CALayer onPause]: unrecognized selector sent to instance 0x1e56ac50 > {code} > The code which register the notification could be found at the end of the > file in the selector {{[CDVConnection initWithWebView:]}}. > The versions 2.0.0 and 2.1.0 does NOT cleanup "only" the two mentioned > events. Like you see in line 139: > https://github.com/apache/incubator-cordova-ios/blob/2.0.0/CordovaLib/Classes/CDVConnection.m#L139 > https://github.com/apache/incubator-cordova-ios/blob/2.1.0/CordovaLib/Classes/CDVConnection.m#L139 > The current HEAD do additionally NOT remove the the event > {{kReachabilityChangedNotification}} from line 113 which should result in > another new bug in the upcoming version. > https://github.com/apache/incubator-cordova-ios/blob/master/CordovaLib/Classes/CDVConnection.m#L113 > To fix this it's enough to add these removeObservers calls again to the > dealloc method. > {code} > [[NSNotificationCenter defaultCenter] removeObserver:self > name:kReachabilityChangedNotification object:nil]; > [[NSNotificationCenter defaultCenter] removeObserver:self > name:UIApplicationDidEnterBackgroundNotification object:nil]; > [[NSNotificationCenter defaultCenter] removeObserver:self > name:UIApplicationWillEnterForegroundNotification object:nil]; > {code} > In generally it's would also be possible to remove the instance in CDVPlugin > for all events!? This would allow you to remove many code from many different > plugins and ensure that no other plugin forget these cleanup. > {code} > [[NSNotificationCenter defaultCenter] removeObserver:self]; > {code} -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators For more information on JIRA, see: http://www.atlassian.com/software/jira