收到远程通知并且用户采取操作(关闭/关闭除外)后,应用程序委托(delegate)将获取回调:
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
或者如果应用程序注册了通知操作:
-(void) application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
我的问题是,当收到远程通知时,应用程序是否会得到回调?那是在用户采取任何操作之前。感谢您的投入。
最佳答案
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")
}
}
关于ios - 收到远程通知时是否有对应用程序委托(delegate)的回调?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37014057/