2017-03-09 20 views
0

我最近开始使用OneSignal在基于Firebase的iOS项目上发送通知。OneSignal在Swift 3中使用Firebase将自动通知发送到网段的身份验证

虽然我可以向特定用户和用户阵列发送通知,但我无法找到有关如何使用Firebase设置OneSignal身份验证的文档,以便我可以通过应用程序自动定位特定的用户群。

,我使用,以向用户发送通知的数组中的代码(做工精细):

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

然而,当我尝试将通知发送到段,像这样:

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

我得到这个错误:

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

我知道,我得到这个错误是由于授权问题,所以我想知道是否有人知道如何使用Firebase设置此授权?

非常感谢!

回答

0

您实际上正在收到此错误,因为您无法使用“included_segments”作为您应用中的定位参数。

您只能使用“include_player_ids”。

文档浏览: https://documentation.onesignal.com/docs/ios-native-sdk#section--postnotification-

如果你想针对用户的细分,可以从仪表板这样做: https://documentation.onesignal.com/docs/sending-notifications#section-selecting-users

或从OneSignal REST API: https://documentation.onesignal.com/v3.0/reference#section-send-to-segments