0
我正在使用帶有Swift(帶橋頭)的Sinch進行即時消息傳遞,並且在收到消息時我沒有收到任何推送通知。使用Sinch和Swift進行iOS推送通知
- 我在Sinch儀表板中有開發證書。
- 禁用背景模式。與其他方式(推進器)
- 推送通知工作
但是,當我發送sinch即時消息應用程序委託的「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)
}
只有當我打開應用程序時纔會收到即時消息。
你說的背景模式是禁用的...所以是的,它只會在收到前景。如果你希望它發生在應用程序在後臺,那麼你必須啓用**後臺提取**請參閱[這裏](https://stackoverflow.com/questions/42275060/what-is-difference-between-remote-notification- and-silent-notification-in-ios/42302369#42302369)1.您是否試圖實施無聲通知或遠程通知? 2.你知道自iOS 10以來有一個新的'UserNotifications'框架嗎?見[這裏](https://stackoverflow.com/questions/37956482/registering-for-push-notifications-in-xcode-8-swift-3-0) – Honey
嗨@Honey謝謝你的幫助,我正在實施用於Sinch的遠程通知,就像我說過的,我可以使用Pusher推送通知,但是應該管理遠程推送通知的Sinch在用戶收到新消息時不會推送通知(我試圖啓用後臺提取,但它不起作用) –
1.您是否還啓用了「遠程通知1」和「背景獲取」?如果現在不讓它們都啓用...... 2.另外,如果你在iOS 10上......那麼你的'didReceiveRemoteNotification'方法將不會被調用。請參閱[這裏](https://stackoverflow.com/q/39382852/5175709) – Honey