开发者

Handling NSNotificationCenter notification is causing bad_access

开发者 https://www.devze.com 2023-03-17 03:28 出处:网络
I am subclassing the UIWindow of my app then when there is no activity from user I raise a notification using NSNotificationCenter.I am using

I am subclassing the UIWindow of my app then when there is no activity from user I raise a notification using NSNotificationCenter. I am using [NSTimer scheduledTimerWithTimeInterval:target:selector: 开发者_StackOverflow userInfo:repeats:]

I handle this in my AppDelegate class. This works OK except when I am running code using MBProgressHUD - http://iosdevelopertips.com/open-source/ios-open-source-heads-up-display-with-mbprogresshud.html which I think starts another thread. Error occurs when it's Done delegate fires the same time as when code that reacts to the Notification is running. I am pretty sure this is a threading issue but how do I avoid the situation


You could use @synchronized on app delegate. Since app delegate is a singletone you'll have to critical sections guarded by it: one in "done delegate" and another in your app delegate.

More info in apple threading documents here

EDIT: this link about threading and notifications is a good source of information for you.

EDIT 2: this one is even better

0

精彩评论

暂无评论...
验证码 换一张
取 消