当用户向同一应用程序中的另一个用户发送通知时,我的通知工作正常。
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")
})
但是,当我需要使用上面的代码从驱动程序(一个应用程序)向用户(另一个应用程序)发送通知时,该用户将不会收到该通知。我相信我需要在上面的代码中添加其余的API密钥或OneSignal应用ID,但我不知道如何。谁能告诉我我需要添加什么代码?
更新:我找到了解决方案。只需添加:“” app_id“:”应用程序ID“,
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool
在上述方法中,您需要设置所有这些参数
// must be Replace 'YOUR_APP_ID' with your OneSignal App ID.
OneSignal.initWithLaunchOptions(launchOptions,
appId: "YOUR_ONESIGNAL_APP_ID",
handleNotificationAction: nil,
settings: onesignalInitSettings)