使用OneSignal推送通知服务将推送通知发送到特定的测试设备

时间:2016-06-22 16:19:46

标签: ios xcode notifications apple-push-notifications onesignal

我之前使用OneSignal为我的iOS应用添加了推送通知支持。该应用程序是使用Swift在Xcode中制作的。

我想只向我的测试设备发送测试推送通知。我在文档中找到了以下手册:How do I send a notification to a single user?

我成功创建了细分受众群,但我不知道在哪里放置这段代码:OneSignal.sendTag("is_test", "true")

有人知道我必须把这段代码放在哪里才能使它像我上面描述的那样工作吗?

我在此处上传了我的代码:https://codeshare.io/DxcNn

谢谢, 大卫。

更新

OneSignal现在还支持将设备设置为测试设备,而无需在代码中执行任何操作。您也可以从App Store下载自己的应用程序并将其用作测试设备。只需从设备中选择您的设备列出一个OneSignal并将其标记为测试设备。您可以按型号,版本和/或时间添加列表中的设备。

1 个答案:

答案 0 :(得分:0)

sendTag方法来自设备sdk。在你的情况下iOS。 https://documentation.onesignal.com/docs/ios-native-sdk#section--sendtag-

您应该在app委托中的initWithLaunchOptions之后随时执行此操作。根据评论更新了代码

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {

        let oneSignal = OneSignal(launchOptions: launchOptions, appId: "here_is_my_onesignal_app_id") { (message, additionalData, isActive) in
            NSLog("OneSignal Notification opened:\nMessage: %@", message)

            if additionalData != nil {
                NSLog("additionalData: %@", additionalData)
                // Check for and read any custom values you added to the notification
                // This done with the "Additonal Data" section the dashbaord.
                // OR setting the 'data' field on our REST API.
                if let customKey = additionalData["customKey"] as! String? {
                    NSLog("customKey: %@", customKey)
                }
            }


        }
        OneSignal.defaultClient().sendTag("is_test", value: "true")

        // Override point for customization after application launch.
        return true
    }