【发布时间】:2017-05-28 20:01:19
【问题描述】:
我查看了 OneSignal 文档,但作为初学者,我无法清楚地理解如何在 iOS Native SDK 中将字典设置为发布通知的附加数据(如 postID、userID、类型),以便在用户与通知交互时决定和重定向。
为了发帖,我只是这样做:
OneSignal.sendTag("username", value: "\(user)")
OneSignal.postNotification(["contents": ["en": "@\(user) added an additive to your '\(title)' experience: \"\(strLast)\""],
"include_player_ids": [postOwnerPlayerID],
接收:
OneSignal.initWithLaunchOptions(launchOptions, appId: "______", handleNotificationReceived: nil, handleNotificationAction: {
(result) in
// This block gets called when the user reacts to a notification received
let payload = result?.notification.payload
//Try to fetch the action selected
if let additionalData = payload?.additionalData {
print("payload")
print(additionalData)
}
// After deciding which action then I can redirect user..
let username: String? = UserDefaults.standard.string(forKey: KEY_UID)
if username != nil {
if let tabbarController = self.window!.rootViewController as? UITabBarController {
tabbarController.selectedViewController = tabbarController.viewControllers?[2]
// NotificationCenter.default.post(name: Foundation.Notification.Name(rawValue: "notificationsUp"), object: nil)
}
}
}, settings: [kOSSettingsKeyInFocusDisplayOption : OSNotificationDisplayType.none.rawValue])
【问题讨论】:
标签: ios swift push-notification onesignal