iOS Swift Twilio可编程聊天推送通知

时间:2017-01-25 23:44:06

标签: ios swift push-notification twilio

使用TwilioChatClient窗格,我已成功将我的应用注册到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)按预期工作。

1 个答案:

答案 0 :(得分:0)

Twilio开发者传道者在这里。

我已经与可编程聊天团队进行了交谈,这是我发现的:

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

关注这些新增内容的Programmable Chat Changelog

让我知道这是否有帮助。

相关问题