ios 7 Push Notification didReceiveRemoteNotification method run on UI thread or separate thread?

ぃ、小莉子 提交于 2019-12-12 02:55:31

问题


(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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!