收到远程通知并且用户采取行动(关闭/解除除外)后,应用委托获得回调:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(无效 (^)(UIBackgroundFetchResult))completionHandler
或者如果应用程序已注册通知操作:
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler :( void (^)())completionHandler
我的问题是,当收到远程通知时应用程序是否收到回调?那是在用户采取任何行动之前。感谢您的投入。
答案 0 :(得分:1)
不,该应用程序未获得通知已到达设备的任何迹象。如您在问题中的两个案例中所描述的那样,只有在通知实际发送到应用程序时才会收到委托调用。
答案 1 :(得分:0)
extension AppDelegate: UNUserNotificationCenterDelegate {
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert,.sound,.badge])
print("NOtification received")
}
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
print("original body was : \(response.notification.request.content.title)")
print("Tapped in notification")
}
}
答案 2 :(得分:0)
可以使用后台更新通知,如https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app 但是,此解决方案的用例受到允许以这种方式发送的通知数量很少的限制(文档当前声明“不要尝试每小时发送超过 2 或 3 个”)。
答案 3 :(得分:-1)
是的,当然,当收到远程通知时,app会收到以下代理方法的回调。
func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
print("DEVICE TOKEN = \(deviceToken)")
}
func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
print(error)
}
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
print(userInfo)
}