我正在安排本地通知。它在iOS 9.x中工作,但从iOS 10开始
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification当应用程序在iOS 10上运行时不会被调用。
我知道iOS引入了新的UserNotifications框架,但这不应该停止iOS 9 API的工作。
我怎样才能解决这个问题?
发布于 2017-04-11 16:07:22
如您所知,iOS 10引入了UNUserNotifications框架来处理本地和远程通知。使用此框架,您可以设置委托以检测通知何时出现或被窃听。
[UNUserNotificationCenter currentNotificationCenter].delegate = yourDelegate;..。
// In your delegate ...
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler {
// Notification arrived while the app was in foreground
completionHandler(UNNotificationPresentationOptionAlert);
// This argument will make the notification appear in foreground
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void (^)())completionHandler {
// Notification was tapped.
completionHandler();
}现在,如果您仍然希望使用旧的(不推荐的) application:didReceiveLocalNotification和application:didReceiveRemoteNotification:fetchCompletionHandler,解决方案很简单:只是不将任何委托设置为UNUserNotificationCenter。
请注意,即使设置了委托,静默远程通知(那些包含content-available键而不包含alert、sound或badge的通知)始终由application:didReceiveRemoteNotification:fetchCompletionHandler处理。
https://stackoverflow.com/questions/39300865
复制相似问题