【问题标题】:Send push notification to a specific test device using OneSignal push notification service使用 OneSignal 推送通知服务向特定测试设备发送推送通知
【发布时间】:2016-06-22 16:19:46
【问题描述】:

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

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

我设法创建了该段,但我不知道将这段代码放在哪里:OneSignal.sendTag("is_test", "true")

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

我在这里上传了我的代码:https://codeshare.io/DxcNn

谢谢, 大卫。

更新:

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

【问题讨论】:

  • 没人能帮我吗?

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


【解决方案1】:

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

您应该在应用委托中的 initWithLaunchOptions 之后随时执行此操作。基于cmets更新代码

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
    }

【讨论】:

  • sendTagsendTags 可以在 initWithLaunchOptions 之后的任何时间调用。即使autoRegister 设置为false,也不必在registerForPushNotifications 之后调用它。
  • 仍然无法正常工作。我正在使用此代码:CodeShare.io。我必须在哪里添加这段代码?代码:OneSignal.sendTag("is_test", "true")
  • 刚刚用代码编辑过。请注意,您需要使用实例调用 oneSignal 而不是类 OneSignal
  • 解决方案是在 oneSignal 代码之外添加以下内容:OneSignal.defaultClient().sendTag("test", value: "true")
猜你喜欢
  • 1970-01-01
  • 2017-10-29
  • 1970-01-01
  • 1970-01-01
  • 2017-01-08
  • 2020-11-02
  • 2016-05-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多