问题描述
我们从UA迁移到One Signal.我们正在从类似云的代码中发送推送
We migrated from UA to One Signal. We are sending push from cloud code like
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中
In my AppDelegate.m I do
[OneSignal initWithLaunchOptions:launchOptions appId:@"XXXXX"];
现在,当收到通知并且用户点击通知时,它曾经用于呼叫
Now earlier when a notification is received and user Taps on it, it used to call
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
问现在没有被调用.我如何使用OneSignal处理它.问:我需要做些什么来处理无提示通知(没有可见的徽章/横幅等)
Q. This is not getting called now. How do I handle it with OneSignal.Q. What I need to do to handle a silent notification (no visible badge/banner etc)
推荐答案
我假设您正在iOS10设备上测试/运行您的应用,
I Assume you are testing/running your app on an iOS10 device,
我查看了OneSignal SDK代码,我认为当设备上检测到iOS10时,SDK会自动使用新的UserNotifications框架(iOS10中已添加).
I looked at OneSignal SDK Code and I think the SDK automatically uses the new UserNotifications Framework (add in iOS10), when iOS10 is detected on device.
在这种情况下,您上面提到的AppDelegate方法不会被调用,而是调用UNUserNotificationCenterDelegate ,SDK会将其捕获以记录点击/观看次数.
In this case, the AppDelegate method you mentioned above does not get invoked, instead methods in UNUserNotificationCenterDelegate get invoked, which are captured by SDK to record clicks/views.
要解决此问题,请创建一个实现OSUserNotificationCenterDelegate
的新类,并使用[OneSignal setNotificationCenterDelegate:yourCustomNotificationCenterDelegateInstance]
To Fix the issue, Create a new class which implements OSUserNotificationCenterDelegate
and provide its instance to OneSignal using [OneSignal setNotificationCenterDelegate:yourCustomNotificationCenterDelegateInstance]
请注意,当无声推送通知(内容可用:1)到达时,仍会调用application:didReceiveRemoteNotification:fetchCompletionHandler:
,但是如果使用UNUserNotificationCenterDelegate
,则用户点击通知时不会调用它.
Please note that application:didReceiveRemoteNotification:fetchCompletionHandler:
is still called when a silent push notification (content-available: 1) arrives, but its not called when user taps the notification if UNUserNotificationCenterDelegate
is used.
此外,iOS 10.0.X上还有一个问题,其中调用了application:didReceiveRemoteNotification
而不是application:didReceiveRemoteNotification:fetchCompletionHandler:
,请参见: https://forums.developer.apple.com/thread/54332 ,但我怀疑您是否是这种情况.
Also, there was an issue on iOS 10.0.X where the application:didReceiveRemoteNotification
was called instead of application:didReceiveRemoteNotification:fetchCompletionHandler:
See: https://forums.developer.apple.com/thread/54332 , but I doubt if this is the case with you.
这篇关于OneSignal不调用didReceiveRemoteNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!