willPresentNotification

willPresentNotification

我使用推送通知,并实现了方法:

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

    NSLog(@"will-present");
}

但是,仅在应用程序处于 Activity 状态而不是后台显示通知时才调用它。当通知即将显示且iPhone屏幕被锁定时,有什么方法可以进行回调?

最佳答案

您需要打开Capabilites中的远程通知的后台模式

ios - willPresentNotification无法按预期工作-LMLPHP

使用此方法在后台处理通知
//handle in this method when app in foreground and background func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {}

关于ios - willPresentNotification无法按预期工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43935776/

10-11 02:36