3
\$\begingroup\$

In Swift, should I be posting notifications to the iOS notification center from the device sending a text message or from the device receiving it?

I'm using OneSignal, so my code to send a notification from the sender device to the receiver device looks like this:

OneSignal.postNotification(["contents": ["en": "You've got a new message from \(sender.name!)"], "include_player_ids": [receiver.notificationId!]], onSuccess: { (dict) in
    //
    print("successfully posted notification")
    print(dict)
}, onFailure: { (error) in
    print("onesignal error!")
    print(error)
})

Alternatively, I can post the notification from the device after it has retrieved the new message from my database (Firebase):

OneSignal.postNotification(["contents": ["en": "You've got a new message from \(cellData.userInfo.fullName)"], "include_player_ids": [self.currentUser.notificationId]], onSuccess: { (dict) in
    //
    print("successfully posted notification")
    print(dict)
}, onFailure: { (error) in
    print("onesignal error!")
    print(error)
})
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.