我们从 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 处理它。 问:我需要做什么来处理静默通知(没有可见的角标(Badge)/横幅等)
最佳答案
我假设您正在 iOS10 设备上测试/运行您的应用,
我查看了 OneSignal SDK 代码,我认为当在设备上检测到 iOS10 时,SDK 会自动使用新的 UserNotifications 框架(在 iOS10 中添加)。
在这种情况下,不会调用您上面提到的 AppDelegate 方法,而是调用 UNUserNotificationCenterDelegate 中的方法被调用,由 SDK 捕获以记录点击/观看。
要解决此问题,请创建一个实现 OSUserNotificationCenterDelegate
的新类,并使用 [OneSignal setNotificationCenterDelegate:yourCustomNotificationCenterDelegateInstance]
将其实例提供给 OneSignal
请注意,application:didReceiveRemoteNotification:fetchCompletionHandler:
在静默推送通知(内容可用:1)到达时仍会被调用,但如果 UNUserNotificationCenterDelegate,当用户点击通知时它不会被调用
被使用。
此外,在 iOS 10.0.X 上存在一个问题,其中调用了 application:didReceiveRemoteNotification
而不是 application:didReceiveRemoteNotification:fetchCompletionHandler:
请参阅:https://forums.developer.apple.com/thread/54332 ,但我怀疑你是否属于这种情况。
关于ios - OneSignal 不调用 didReceiveRemoteNotification,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40600138/