SWIFT IOS通过应用程序发送OneSignal通知
当用户向同一应用程序中的另一用户发送通知时,我的通知工作正常SWIFT IOS通过应用程序发送OneSignal通知,swift,onesignal,Swift,Onesignal,当用户向同一应用程序中的另一用户发送通知时,我的通知工作正常 let userPushId = order?.pushId let jsonMessage: [AnyHashable: Any]! = ["contents": ["en": "is taking your order"], "headings": ["en": self.myUserName ?? "Driver"], "include_player_ids": [userPushId]
let userPushId = order?.pushId
let jsonMessage: [AnyHashable: Any]! = ["contents": ["en": "is taking your order"],
"headings": ["en": self.myUserName ?? "Driver"], "include_player_ids": [userPushId],
"ios_badgeType": "Increase", "ios_badgeCount": 1]
OneSignal.postNotification(jsonMessage, onSuccess: { _ in
print("from\(self.myUserName ?? "") to \(userPushId)")
}, onFailure: { _ in
print("Notification could not be delivered")
})
但是,当我需要使用上述代码从驱动程序(一个应用程序)向用户(另一个应用程序)发送通知时,用户将不会收到通知。我相信我需要在上面的代码中添加RESTAPI密钥或OneSignal应用程序id,但我不知道如何添加。谁能告诉我需要添加哪些代码吗?更新:我找到了解决方案。只需添加:“应用程序id”:“应用程序id” 在上述方法中,您需要设置所有参数
// must be Replace 'YOUR_APP_ID' with your OneSignal App ID.
OneSignal.initWithLaunchOptions(launchOptions,
appId: "YOUR_ONESIGNAL_APP_ID",
handleNotificationAction: nil,
settings: onesignalInitSettings)
// must be Replace 'YOUR_APP_ID' with your OneSignal App ID.
OneSignal.initWithLaunchOptions(launchOptions,
appId: "YOUR_ONESIGNAL_APP_ID",
handleNotificationAction: nil,
settings: onesignalInitSettings)