1

I've followed the docs and have successfully registered for push notifications with Sendbird (uploaded .p12 dev certificate + register device token with Sendbird SDK, etc) but am not getting any notifications.

func application( application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData ) {

    NSUserDefaults.standardUserDefaults().setObject(deviceToken, forKey: "deviceToken")

    SBDMain.registerDevicePushToken(deviceToken) { (status, error) in
        if error == nil {
            if status == SBDPushTokenRegistrationStatus.Pending {

                SBDMain.connectWithUserId("\(UserDataStore.ownerProfile?.id!)", completionHandler: { (user, error) in

                    SBDMain.registerDevicePushToken(SBDMain.getPendingPushToken()!, completionHandler: { (status, error) in
                        print("Sendbird Registration Succeeded 2nd attempt")
                    })
                })

            } else {
                print("Sendbird Registration Succeeded")
            }
        } else {
            print("Sendbird Push Registration Failed")
        }
    }
}

In my didReceive...I'm not getting anything.

 func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {

    if let aps = userInfo["aps"] as? NSDictionary {
        if let alert = aps["alert"] as? NSDictionary {
            if let message = alert["message"] as? NSString {
                print(message)
            }
        } else if let alert = aps["alert"] as? NSString {
            print(alert)
        }
    }

    if application.applicationState ==  .Inactive {
        NSNotificationCenter.defaultCenter().postNotificationName("pushNotificationReceived", object: nil)
    } else {
    NSNotificationCenter.defaultCenter().postNotificationName("pushNotificationReceivedActive", object: nil)
    } 
}

I've done push notifications in the past and am familiar with the process. In fact, I just tested out with Firebase Cloud Messaging and the push works fine with their service. If anyone can help, would be greatly appreciate it...I'm curious to see if there are any additional steps that needs to be taken with Sendbird.

UPDATE: I've reached out to Sendbird and the problem was a bug on their dashboard where you upload the .p12 file; deleting the file and re-uploading fixes the problem. The bug has been patched since.

Tuan Anh Vu
  • 760
  • 1
  • 7
  • 26

2 Answers2

0

SendBird sends push notification to users only if they are offline.

Please confirm that you sent a message to offline users. (e.g. Pressing home button to make app running on background so it becomes offline from SendBird)

Harry Kim
  • 89
  • 5
  • For me push notification from sandbird comes only when the app is in background. But it is not hitting didReceiveRemoteNotification function in app delegate. Actually it is not hitting any function when it is displaying notification – Deepakraj Murugesan Jul 18 '18 at 13:18
0

For those who don't receive the push notifications while the app is running and only receive it in case the user is offline, you have to register a callback handler for channels once the user is connected to receive the messages through a channel delegate, and then you can make a local push notification from there:

class GroupChannelChattingViewController: UIViewController, SBDChannelDelegate {
    SBDMain.add(self as SBDChannelDelegate, identifier: self.delegateIdentifier)

    func channel(_ sender: SBDBaseChannel, didReceive message: SBDBaseMessage) {
        if message is SBDUserMessage {
            // Do something when the received message is a UserMessage.
        }
        else if message is SBDFileMessage {
            // Do something when the received message is a FileMessage.
        }
        else if message is SBDAdminMessage {
            // Do something when the received message is an AdminMessage.
        }
    }
}

This can be found here.

Muhammed Refaat
  • 8,914
  • 14
  • 83
  • 118