0
votes

I recently started using OneSignal to send notifications on my firebase based iOS project.

While I can send notifications to specific user and an array of users fine, I can't find documentation on how to set up OneSignal authentication with Firebase so that I can target a specific segment of users automatically through the app.

The code that I am using to send notifications to an array of users (working fine):

    //to remove the current user ("playerID") from receiving notification
    let indexToDelete = playerIDArray.index(of: playerID)

    playerIDArray.remove(at: indexToDelete!)

    var count = 0

    while count < playerIDArray.count {

        OneSignal.postNotification(["contents" : ["en" : "\(usersID!) has sent a message"], "include_player_ids" : ["\(playerIDArray[count])"]])

        count = count+1
    }

However, when I try to send the notification to a segments, like so:

     OneSignal.postNotification(["contents" : ["en" : "\(usersID!) has sent a message"], "included_segments" : ["All"]])

I get this error:

2017-03-09 02:35:30.989 MyApp[3658:87978] ERROR: Create notification failed

I know that I am getting this error due to authorization issues, so I was wondering if anyone knows how to set up this authorization using Firebase?

Thanks so much!

1

1 Answers

0
votes

you are actually getting this error because you cannot use "included_segments" as a targeting parameter from you app.

You can only use "include_player_ids".

Documentation here: https://documentation.onesignal.com/docs/ios-native-sdk#section--postnotification-

If you would like to target segments of users, you may do so from your dashboard: https://documentation.onesignal.com/docs/sending-notifications#section-selecting-users

or from the OneSignal REST API: https://documentation.onesignal.com/v3.0/reference#section-send-to-segments