【发布时间】:2017-06-07 19:09:49
【问题描述】:
我将 Sinch 与 Swift(带有桥接头)一起用于即时消息传递,但在收到消息时我没有收到任何推送通知。
- 我在 Sinch Dashboard 中拥有开发证书。
- 后台模式已禁用。
- 通过其他方式推送通知(Pusher)
但是当我发送一条即时消息时,App Delegate 的“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)
}
只有当我打开应用程序时才会收到即时消息。
【问题讨论】:
-
嗨@Honey 谢谢你的帮助,我正在为Sinch 实现远程通知,就像我说我可以使用Pusher 推送通知但是应该管理远程推送通知的Sinch 不会推送通知用户收到一条新消息(我尝试启用后台提取但没有帮助)
-
1.您是否还启用了“远程通知1s”和“后台获取”?如果现在不让它们都启用... 2. 此外,如果您使用的是 iOS 10...那么您的
didReceiveRemoteNotification方法将不会被调用。见here -
@Honey 1.我尝试启用“远程通知1s”和“后台获取”,但它没有 2.
didReceiveRemoteNotification方法被 Pusher 3 调用。感谢您继续帮助我 -
它被调用了?那么你的问题现在解决了吗?
标签: ios swift apple-push-notifications sinch