[UIActivityIndicatorView _applicationDidEnterBackground:]: message sent to deallocated instance

本文探讨了iOS App在进入后台时遇到的崩溃问题,具体为向已释放的UIActivityIndicatorView发送消息导致崩溃。通过分析代码,发现是引入了第三方库UIKit+AFNetworking导致冲突。建议在不使用UIActivityIndicatorView+AFNetworking时,移除该库以解决问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

[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.youkuaiyun.com/scyatcs/article/details/38108683


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值