ios - 收到远程通知时是否有对应用程序委托(delegate)的回调?

标签 ios push-notification

收到远程通知并且用户采取操作(关闭/关闭除外)后,应用程序委托(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/

相关文章:

ios - 如何向选定的 iPhone 用户发送推送通知?

android - 使用xml内容实现android可扩展通知?

iOS:使用 Amazon SNS 以编程方式从应用触发推送通知

android - cordova 3.3 中的用户推送通知

ios - 切换 NSPersistentStore 文件时的 Core Data 延迟

ios - WKWebView 缩放无法正常工作

iphone - CLLocationManager 地理编码地址字符串 :inRegion not working to constrain region (ios5)

ios - Swift 3 - 多 View Controller 错误

ios - 如何在 swift 中为 Post 请求创建 JSON Body

Firebase 消息传递/凭据不匹配