我使用 Sinch 和 Swift(带有桥接 header )进行即时消息传递,但在收到消息时没有收到任何推送通知。
- 我拥有 Sinch Dashboard 的开发证书。
- 后台模式已禁用。
- 推送通知以其他方式工作(Pusher)
但是当我发送一条即时消息时,应用程序代理的“didReceiveRemoteNotification”函数永远不会被调用。
var sinClient:SINClient?
var push:SINManagedPush?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//Sinch Push Notification
sinClient = Sinch.client(withApplicationKey: "-----", applicationSecret: "------", environmentHost: "sandbox.sinch.com", userId: "----")
sinClient?.setSupportMessaging(true)
sinClient?.enableManagedPushNotifications()
sinClient?.delegate = self
sinClient?.messageClient().delegate = self
sinClient?.start()
sinClient?.startListeningOnActiveConnection()
self.push = Sinch.managedPush(with: SINAPSEnvironment.development)
self.push?.delegate = self
self.push?.setDesiredPushTypeAutomatically()
self.push?.registerUserNotificationSettings()
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data -> String in
return String(format: "%02.2hhx", data)
}
let token = tokenParts.joined()
print("Device Token: \(token)")
self.push?.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
self.push?.application(application, didReceiveRemoteNotification: userInfo)
}
func managedPush(_ managedPush: SINManagedPush!, didReceiveIncomingPushWithPayload payload: [AnyHashable : Any]!, forType pushType: String!) {
sinClient?.relayRemotePushNotification(payload)
}
仅当我打开应用程序时才会收到即时消息。
最佳答案
最后发现问题出在我用模拟器发送消息
关于使用 Sinch 和 Swift 进行 iOS 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44420947/