0

I am using Sinch with Swift (with bridging header) for instant messaging and I don't receive any push notification when a message is received.

  • I have a Development Certificate in the Sinch Dashboard.
  • Background modes are disabled.
  • Push notification work with other way (Pusher)

But when I send a sinch instant message the App Delegate's "didReceiveRemoteNotification" function never gets called.

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)
    }

Instant Message are received only when I open the app.

Jim Derman
  • 11
  • 1
  • you said background modes are disabled...so yes it would only be received in foreground. If you want it to happen when app is in background then you must enable **background fetch** see [here](https://stackoverflow.com/questions/42275060/what-is-difference-between-remote-notification-and-silent-notification-in-ios/42302369#42302369) 1. Are you trying to implement Silent notifications or Remote notifications? 2. Do you know there is a new `UserNotifications` framework since iOS 10? See [here](https://stackoverflow.com/questions/37956482/registering-for-push-notifications-in-xcode-8-swift-3-0) – mfaani Jun 07 '17 at 19:17
  • Hi @Honey thank you for your help, I am implementing Remote notifications for Sinch,like I said I can push notification with Pusher but Sinch which supposed to manage remote push notification doesn't push a notification when the user receive a new message (I tried to enable background fetch but it doesn't help) – Jim Derman Jun 08 '17 at 11:33
  • 1. Do you also have "remote notification1s" & "background fetch" enabled? If not keep them both enabled for now... 2. Additionally if you're on iOS 10...then your `didReceiveRemoteNotification` method won't get called. See [here](https://stackoverflow.com/q/39382852/5175709) – mfaani Jun 08 '17 at 14:02
  • @Honey 1.I try to enable "remote notification1s" & "background fetch" but it doesn't 2. `didReceiveRemoteNotification` method get called with Pusher 3.Thank you for continuing to help me – Jim Derman Jun 08 '17 at 21:13
  • It gets called? So is your problem solved now? – mfaani Jun 08 '17 at 21:43
  • @Honey it gets called with Pusher but Sinch which suppose to manage the notification doesn't call the function when an instant message is received – Jim Derman Jun 11 '17 at 11:54
  • facing same problem can someone help really appreciate – Meet Ios Developer Jun 21 '20 at 18:18

1 Answers1

1

Finally I found that the problem was that I used the simulator to send the message

Jim Derman
  • 11
  • 1