OneSignal不调用didReceiveRemoteNotification
我们从UA迁移到了One Signal。 我们正在从云代码推送像
var pushInfo = { "app_id" : "xxxxxx", "data": { "objectId": objectId, "placeId": placeId, }, "included_segments": ["All Users"], "contents": {"en": message} }; var headers = { "Content-Type": "application/json; charset=utf-8", "Authorization": "Basic XXXXX" }; var options = { host: "onesignal.com", port: 443, path: "/api/v1/notifications", method: "POST", headers: headers, }; var https = require('https'); var req = https.request(options, function(res) { res.on('data', function(data) { console.log("Response:"); console.log(JSON.parse(data)); }); }); req.on('error', function(e) { console.log("ERROR:"); console.log(e); }); req.write(JSON.stringify(pushInfo)); req.end();
在我的AppDelegate.m我做的
[OneSignal initWithLaunchOptions:launchOptions appId:@"XXXXX"];
现在,在收到通知并且用户点击它之前,它曾经打电话
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
问:现在没有得到调用。 我如何处理它与OneSignal。 问:我需要做什么来处理一个安静的通知(没有可见的徽章/横幅等)
我假设您正在iOS10设备上testing/运行您的应用程序,
我查看了OneSignal SDK代码,我认为当设备上检测到iOS10时,SDK会自动使用新的UserNotifications Framework(在iOS10中添加)。
在这种情况下,上面提到的AppDelegate方法不会被调用,而是调用UNUserNotificationCenterDelegate中的方法,由SDK捕获这些方法来logging点击/视图。
为了解决这个问题,创build一个实现OSUserNotificationCenterDelegate
的新类,并使用[OneSignal setNotificationCenterDelegate:yourCustomNotificationCenterDelegateInstance]
其实例提供给OneSignal。
请注意, application:didReceiveRemoteNotification:fetchCompletionHandler:
在静默推送通知(content-available:1)到达时仍然被调用,但是如果在使用UNUserNotificationCenterDelegate
时用户点击通知,则不会调用它。
此外,在iOS 10.0.X上, application:didReceiveRemoteNotification
didReceiveRemoteNotification被调用,而不是application:didReceiveRemoteNotification:fetchCompletionHandler:
请参阅: https application:didReceiveRemoteNotification:fetchCompletionHandler:
,但我怀疑这是与你的情况。
application:didReceiveRemoteNotification:fetchCompletionHandler:
是背景无声content-available
通知的正确select器。 请确保您使用的是最新的2.2.2 OneSignal SDK,因为有一些修复程序可以保持与旧AppDelegateselect器的兼容性。
您可能想要考虑使用UNNotificationServiceExtension与iOS 10设备的mutable-content
,因为这仍然适用于应用程序已被刷新。