【问题标题】:iOS push notification using Sinch with Swift使用 Sinch 和 Swift 的 iOS 推送通知
【发布时间】: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)
    }

只有当我打开应用程序时才会收到即时消息。

【问题讨论】:

  • 你说后台模式被禁用...所以是的,它只会在前台接收。如果您希望它在应用程序处于后台时发生,那么您必须启用 background fetch 请参阅here 1.您是在尝试实现静默通知还是远程通知? 2. 你知道iOS 10 之后有一个新的UserNotifications 框架吗?见here
  • 嗨@Honey 谢谢你的帮助,我正在为Sinch 实现远程通知,就像我说我可以使用Pusher 推送通知但是应该管理远程推送通知的Sinch 不会推送通知用户收到一条新消息(我尝试启用后台提取但没有帮助)
  • 1.您是否还启用了“远程通知1s”和“后台获取”?如果现在不让它们都启用... 2. 此外,如果您使用的是 iOS 10...那么您的 didReceiveRemoteNotification 方法将不会被调用。见here
  • @Honey 1.我尝试启用“远程通知1s”和“后台获取”,但它没有 2.didReceiveRemoteNotification 方法被 Pusher 3 调用。感谢您继续帮助我
  • 它被调用了?那么你的问题现在解决了吗?

标签: ios swift apple-push-notifications sinch


【解决方案1】:

最后发现问题是我用模拟器发消息

【讨论】:

  • 在 sinch 背景中遇到问题你能帮忙
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多