简体   繁体   中英

iOS: is calling methods of UIApplication in thread other than the main thread safe?

Some say that one must use UIApplication in main thread, but I don't see this documented in Apple's doc. So can someone please tell me if it is safe to use UIApplication in a separate thread? If it is not safe, where is this documented?

EDIT: I'm focusing on those methods which manipulate local notifications.

Most UIKit classes are not thread safe. This has been discussed at length at WWDC, etc, but it is not very well documented. The best I could find is TN2109 which repeatedly discusses how calling UIKit from a secondary thread is not permitted.

Note that there are many documented exceptions to this rule. For example, the beginBackgroundTaskWithExpirationHandler and related methods on UIApplication are clearly labeled as safe to call from non-main threads. (This also implies that the other methods of UIApplication are not safe to call from other threads, since these are specifically called out.)

There are other exceptions to this rule as well, mostly involving drawing (UIImage, and UIColor instances are thread-safe, as of iOS 4 , at least).

UIApplication is a subclass of UIResponder and is part of the UIKit framework. So I guess it is not thread safe because it is documented that UIKit classes are not thread safe.

Also it has methods like – setStatusBarOrientation:animated:, which are all UI based and those definitely cannot be called in another thread than the main thread.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM