2016-12-02 30 views
2

描述 - Uptil的iOS 9,下列方法被調用如何在iOS 10中收到後臺通知?

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 

但是從iOS的10,蘋果提供了新的框架,即userNotification.framework 和新的方法來處理,即

// The method will be called on the delegate only if the application is in the foreground. If the method is not implemented or the handler is not called in a timely manner then the notification will not be presented. The application can choose to have the notification presented as a sound, badge, alert and/or in the notification list. This decision should be based on whether the information in the notification is otherwise visible to the user. 

- (void)userNotificationCenter:(UNUserNotificationCenter *)center 
     willPresentNotification:(UNNotification *)notification 
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler 

// The method will be called on the delegate when the user responded to the notification by opening the application, dismissing the notification or choosing a UNNotificationAction. The delegate must be set before the application returns from applicationDidFinishLaunching:. 

- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler 

但現在我無法在應用程序處於後臺並且用戶未單擊時收到通知回調通知。

我想要的是,當用戶在後臺,如果他收到任何通知,然後在哪種方法,我會收到回電的收到通知。

在此先感謝。

回答

2

在iOS10,willPresent將在應用程序運行前景時調用。 didReceive將在用戶在運行後臺時點擊通知時被調用。

如果您想在應用程序正在運行的背景處理通知,你仍然需要實現didReceiveRemoteNotification ... fetchCompletionHandler,不要忘了「內容提供」添加到您的通知有效載荷。將其設置爲1.

相關問題