问题
(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
method run on UI Thread or separate background thread? Because I need to process data based on push message and store in local database table using Core Data. If I do Core Data operations in this method,it will disturb the UI or not?
回答1:
every application delegate method run on main thread only. try to avoid doing big task over there. if its small task it wont disturb the ui.
回答2:
application(_:didReceiveRemoteNotification:fetchCompletionHandler:) is part of UIKit, which is tied to the UI thread:
Use UIKit classes only from your app’s main thread or main dispatch queue, unless otherwise indicated. This restriction particularly applies to classes derived from UIResponder or that involve manipulating your app’s user interface in any way.
UIKit follows its own rules by calling this method from the UI thread. This makes it easy to use other UIKey methods, but you are responsible for ensuring that your method returns quickly.
回答3:
(void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
method run on separate background thread because when we are using our application than notification received by application. So its means this method run on separate background thread.
来源:https://stackoverflow.com/questions/20896993/ios-7-push-notification-didreceiveremotenotification-method-run-on-ui-thread-or