gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 08:18:42 26 4
gpt4 key购买 nike

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

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

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

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) 按预期工作。

最佳答案

此处为 Twilio 开发人员布道师。

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

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

关注Programmable Chat Changelog对于这些添加。

让我知道这是否有帮助。

关于iOS Swift Twilio 可编程聊天推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41863736/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com