[UIActivityIndicatorView _applicationDidEnterBackground:]: message sent to deallocated instance

来源:互联网 发布:se壳网络验证 编辑:程序博客网 时间:2024/05/29 18:27

[UIActivityIndicatorView _applicationDidEnterBackground:]: message sent to deallocated instance


当我们运行我的的App 时,App不会crash,可当我们一按home 键,或者锁屏时,App 就会 crash  ,利用zombie 可以捕获如上信息。由信息中可得,app 向一个已经被释放的UIActivityIndicatorView发送了一个消息,导致crash。最后检查到原来是是使用的第三方包UIKit+AFNetWorking  导致的,

再   UIActivityIndicatorView+AFNetworking.m 中,有如下代码,


-(void)dealloc

{

    NSNotificationCenter *notificationCenter = [NSNotificationCenterdefaultCenter];

#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 70000

    [notificationCenter removeObserver:selfname:AFNetworkingTaskDidCompleteNotificationobject:nil];

    [notificationCenter removeObserver:selfname:AFNetworkingTaskDidResumeNotificationobject:nil];

    [notificationCenter removeObserver:selfname:AFNetworkingTaskDidSuspendNotificationobject:nil];

#endif

    

    [notificationCenter removeObserver:selfname:AFNetworkingOperationDidStartNotificationobject:nil];

    [notificationCenter removeObserver:selfname:AFNetworkingOperationDidFinishNotificationobject:nil];

}


那就很明显了,当App 进入后台,UIActivityIndicatorView 被释放,当执行这个方法,App 便被crash了。

如果大家引入UIKit+AFNetWorking 时,没有用到UIActivityIndicatorView+AFNetworking ,大可把他移除掉,这样就可以解决上面的问题了。

希望对大家有帮助。


http://blog.csdn.net/scyatcs/article/details/38108683


1 0
原创粉丝点击