简体   繁体   English

iOS 应用程序未收到来自 Twilio 可编程聊天的推送通知

[英]iOS app not receiving push notifications from Twilio programmable chat

I have started a new project to try out Twilio programable chat but I'm not able to get the push notifications to work.我开始了一个新项目来试用 Twilio 可编程聊天,但我无法让推送通知工作。

I am using Firebase to handle the push notifications and notifications directly from Firebase are working fine.我正在使用 Firebase 来处理直接来自 Firebase 的推送通知和通知工作正常。

Now here's how I've configured everything:现在这是我配置一切的方式:

I am using a Twilio function for my chat to work.我正在使用 Twilio 功能进行聊天。 I've created an FCM push credential on Twilio dashboard and when asked for the FCM SECRET I've added the Server key that was inside the Cloud Messaging Settings on Firebase console.我在 Twilio 仪表板上创建了一个 FCM 推送凭证,当被要求提供FCM SECRET我添加了 Firebase 控制台上Cloud Messaging SettingsServer key

I have updated the push notification configuration to enable notifications on a new message on the dashboard like this:我更新了推送通知配置,以便在仪表板上的新消息上启用通知,如下所示:

Twilio 通知仪表板屏幕截图

On the app I do have push notifications working, because I am able to receive notifications directly from Firebase.在应用程序上,我确实有推送通知工作,因为我能够直接从 Firebase 接收通知。

I've registered for remote notifications on didFinishLaunchingWithOptions like this:我已经在 didFinishLaunchingWithOptions 上注册了远程通知,如下所示:

UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { _, _ in }
application.registerForRemoteNotifications()

On AppDelegate I'm actually receiving the device token, storing it for later and setting it on my chat client在 AppDelegate 上,我实际上收到了设备令牌,将其存储以备后用并在我的聊天客户端上进行设置

static var token: Data?

func application(_: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        AppDelegate.token = deviceToken
}

After that, when I'm creating my chat client, I set the device token and the callback's result is successful之后,当我创建我的聊天客户端时,我设置了设备令牌并且回调的结果是成功的

func signIn(identity: String) {
        self.identity = identity
        tokenService.retrieveToken(identity: identity) { result in
            if case let .success(token) = result {
                TwilioChatClient.chatClient(withToken: token, properties: nil, delegate: self) { _, client in
                    self.client = client
                    if let pushToken = AppDelegate.token {
                        client?.register(withNotificationToken: pushToken) { result in
                            print(result.isSuccessful()) // this prints true
                        }
                    }
                }
            }
        }
    }

After all this setup I'm still not able to receive push notifications, so I'm not sure if I'm doing something wrong or if I'm missing something完成所有这些设置后,我仍然无法接收推送通知,所以我不确定是我做错了什么还是遗漏了什么

I have had similar issue.我有过类似的问题。 My problem was that I was not able to receive push notifications on iOS 13.我的问题是我无法在 iOS 13 上接收推送通知。

For me the solution was to update the Twilio SDK within iOS Project.对我来说,解决方案是在 iOS 项目中更新 Twilio SDK

Right now it is v.4.0.0现在是 v.4.0.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM