【问题标题】:iOS Swift Twilio Programmable Chat Push NotificationsiOS Swift Twilio 可编程聊天推送通知
【发布时间】:2017-01-25 23:44:05
【问题描述】:

使用 TwilioChatClient pod,我已成功将我的应用程序注册到 Twilio Programmable Chat 以接收 APN 通知。

但是,据我所知,这些通知是在实例化的 TwilioChatClient 客户端上调用 client.register(withToken: deviceToken) 后创建的,而不是通过应用程序的 AppDelegate didReceiveRemoteNotification 方法创建的。更奇怪的是,didReceiveRemoteNotification 被调用,但仅在应用程序处于活动状态而不是后台状态时,我想执行一些操作。

有谁知道这些通知是在哪里以及如何创建的,或者为什么didReceiveRemoteNotification 只在活动状态下被调用?除其他外,我想随着客户端发出的每个通知增加应用程序图标徽章编号。

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    print("Registered for notifications");
    if UserUtils.client?.userInfo != nil {
        print("Has info");
        UserUtils.deviceToken = deviceToken;
        UserUtils.client?.register(withToken: deviceToken)
    } else {
        print("No info");
        updatedPushToken = deviceToken as NSData?
    }
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print("Received a notification");
    if UIApplication.shared.applicationState != .active {
        print(userInfo);
        UserUtils.client?.handleNotification(userInfo);
        UIApplication.shared.applicationIconBadgeNumber += 1;
        if UserUtils.client?.userInfo != nil {
            print(userInfo);
            let jsonNotification = JSON(userInfo["aps"])
            let alert = jsonNotification["alert"].stringValue + "\"}";
            print(JSON.init(parseJSON: alert)["body"]);
        } else {
            print(userInfo);
            let jsonNotification = JSON(userInfo["aps"])
            let alert = jsonNotification["alert"].stringValue + "\"}";
            print(JSON.init(parseJSON: alert)["body"]);
        }
    } else {
    }
}

client.register(withToken: deviceToken) 按预期工作。

【问题讨论】:

  • 请添加您的代码sn-ps
  • 您使用哪种didReceiveRemoteNotification 方法?你在用这个application(_:didReceiveRemoteNotification:fetchCompletionHandler:)
  • @muescha,我正在使用包含 fetchCompletionHandler 的方法 - 但我已经尝试了这两种方法,但它们都不适合我。我现在将发布我的代码 sn-ps!
  • 您还看到文档中的最后一段吗?也许这就是为什么?
  • @muescha,您指的是哪个文档?可以给我链接吗?

标签: ios swift push-notification twilio


【解决方案1】:

这里是 Twilio 开发者宣传员。

我与 Programmable Chat 团队交谈过,这是我发现的:

  • application(_:didReceiveRemoteNotification:fetchCompletionHandler:) 用于仅执行后台处理的后台静默通知(即,在 APNS 通知中设置了"content-available": 1)。可编程聊天向用户发送显示信息的通知,因此不会在后台模式下触发
  • 不过,通知可以为您更新徽章计数,所以这是您不必执行的处理,这需要在通知中进行不同的设置,我们目前不支持,但是现在正在努力添加该支持
  • 如果您想同时显示通知并进行进一步的后台处理,常规通知不支持此功能,但 iOS 10 的service extensions 支持此功能。可编程聊天也不支持这些,但同样,它正在开发中,所以你很快就会看到

请留意Programmable Chat Changelog 以了解这些新增内容。

让我知道这是否有帮助。

【讨论】:

    猜你喜欢
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 2018-01-20
    • 2020-12-22
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    相关资源
    最近更新 更多