Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SWIFT IOS通过应用程序发送OneSignal通知_Swift_Onesignal - Fatal编程技术网

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)