【问题标题】:Silent Notification not getting in Application Not Running State?静默通知未进入应用程序未运行状态?
【发布时间】:2018-07-25 05:08:38
【问题描述】:

这是通知负载:

{ 
 "aps": {
   "content-available": "1"
  }, "data": {
     "ct_typ": "1",
     "imp": "0",
     "msg_id": "1532071410494",
     "msg_typ": "0",
     "user_id": "11136cb83e"
 }}

我使用以下方法并在后台模式下获得通知,但此方法在 Not Running(Kill Mode) 下不起作用。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {}

我正在使用 XMPP,我需要在未运行(终止模式)上回复传递的消息。

【问题讨论】:

  • 你为什么使用静默通知?您应该使用普通通知并创建通知内容扩展。从那里您可以重播有关消息传递的发件人。

标签: ios swift apple-push-notifications xmpp xmppframework


【解决方案1】:

如果应用程序被用户强行终止,则静默通知将不起作用。为此,您应该使用正常通知。这样,即使您的应用被终止,也会显示新消息的通知。

通过创建通知服务扩展,即使您的应用被终止,您也可以控制。

Notification service extension 在这里查看更多信息。

【讨论】:

  • 我已实现通知服务扩展并收到通知,但服务扩展方法不要求下载内容。所以你能帮我解决我想念的事情吗?
  • 如果你想在通知上下载一些东西。您可以这样做,甚至可以为扩展安装 pod。但是要在您的应用程序和扩展程序之间传递数据,您需要使用组用户默认值。
【解决方案2】:

从 iOS 10 及更高版本开始,您已将 UIUserNotification 委托方法用于最新的操作系统。在活动中接收通知的委托方法如下。我认为您使用旧代码进行通知。

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent
    notification: UNNotification, withCompletionHandler completionHandler:
    @escaping (UNNotificationPresentationOptions) -> Void) {

    return completionHandler(UNNotificationPresentationOptions.alert)
}

How to implement Remote notification for iOS 10 and later.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 2018-03-30
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多