OneSiganl for iOS 10的通知无效 . 我再次重新检查我正在使用的东西..
Xcode 8.1,Swift 3,添加了最新的配置证书,功能推送通知已启用权利,
我的app委托方法是
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
OneSignal.initWithLaunchOptions(launchOptions, appId: ONE_SIGNAL_APPID)
OneSignal.setLogLevel(.LL_VERBOSE, visualLevel: .LL_NONE)
OneSignal.promptLocation();
OneSignal.initWithLaunchOptions(launchOptions, appId: ONE_SIGNAL_APPID, handleNotificationReceived: {
(Notification) in
}, handleNotificationAction: { (action) in
}, settings:[kOSSettingsKeyAutoPrompt: true ,
kOSSettingsKeyInFocusDisplayOption:OSNotificationDisplayType.notification.rawValue]) }
并且用于注册具有id的设备 .
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
OneSignal.sendTag("myType", value: "myBroadCast")
OneSignal.idsAvailable { (userId, deviceToken) in
let userId = String(format: "%@", userId!)
DataManager.sharedInstance.deviceToken = userId;
print("player id",userId)
}
我有明显的播放器,即userId . 所以我的设备已成功注册 .
问题是我的设备上没有收到api通知 . 除了OneSignal样本推送消息(工作正常),
我的通知API有效负载是
{"alert":{"notification":{"notification_type":1,"v_n":"Custom Place","u_n":"customer","c_id":907,"m_id":1207,"m_t":"1","f_a":0,"d_d":"07 Dec, 2016","t_t":"07:40 AM","is_group_chat":true},"body":"hxuf"},"badge":1,"sound":"NewMessage.mp3"}
请帮助我这方面 . 由于此问题仅适用于iOS 10设备 .
1 回答
如果您对https://onesignal.com/api/v1/notifications进行POST REST API调用,则JSON格式不正确 . 根据您问题中JSON示例中的内容,OneSignal通知的JSON有效负载应如下所示 .
Note1: 您必须将目标参数(如
include_player_ids
)设置为一个JOSN数组,并将其设置为OneSignal播放器/用户ID列表 . 或使用其他定位参数,例如included_segments
. 请参阅本答复底部的OneSignal文档页面中的完整的tarting选项 .Note2: .mp3文件不能用于iOS的通知声音 . 您必须将其转换为.wav或.caf格式 .
请参阅下面的OneSignal关于创建REST API调用 endpoints 的完整文档 . https://documentation.onesignal.com/reference#create-notification