【问题标题】:iOS Push Notifications: How to get the "Notification identifier" within the delegateiOS推送通知:如何在委托中获取“通知标识符”
【发布时间】:2014-06-18 02:27:58
【问题描述】:

当我通过 APN 向我的 iOS 应用程序发送推送通知时,大多数情况下一切正常。将收到通知,我可以从application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 方法的userInfo 字典中读取有效负载。

userData 不包含通知标识符,这是自 iOS 7 以来新通知格式的一部分,尽管 Apple 是这样描述 userInfo 的:

包含与远程通知相关信息的字典,可能包括应用图标的徽章编号、警报声音、要向用户显示的警报消息、通知标识符和自定义数据。

那么,在发送通知后,有什么方法可以从我的应用程序中获取通知标识符?还是该标识符仅由反馈服务使用?

【问题讨论】:

  • 你收到通知标识符了吗

标签: ios push-notification apple-push-notifications


【解决方案1】:

使用 iOS 10 中引入的新 API UNUserNotificationCenterDelegate。 在UNUserNotificationCenter上设置Delegate,收到推送消息时调用如下方法。

func userNotificationCenter(_ center: UNUserNotificationCenter, 
                          didReceive response: UNNotificationResponse, 
               withCompletionHandler completionHandler: @escaping () -> Void)

在那里你可以找到UNNotificationResponse中的所有内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 2011-08-07
    • 1970-01-01
    相关资源
    最近更新 更多