use*_*140 4 push-notification apple-push-notifications ios onesignal
我们从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();
Run Code Online (Sandbox Code Playgroud)
在我的AppDelegate.m中
[OneSignal initWithLaunchOptions:launchOptions appId:@"XXXXX"];
Run Code Online (Sandbox Code Playgroud)
现在,在更早的时候,收到通知并用户点击它时,它曾经用于呼叫
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
Run Code Online (Sandbox Code Playgroud)
问:现在没有被调用。我如何使用OneSignal处理它。问:我需要做些什么来处理无提示通知(没有可见的徽章/横幅等)
我假设您正在iOS10设备上测试/运行您的应用,
我查看了OneSignal SDK代码,我认为当设备上检测到iOS10时,SDK将自动使用新的UserNotifications框架(iOS10中添加)。
在这种情况下,不会调用您上面提到的AppDelegate方法,而是将调用UNUserNotificationCenterDelegate中的方法,SDK会捕获这些方法来记录点击/查看。
要解决此问题,请创建一个新类,OSUserNotificationCenterDelegate该类使用以下方法实现并将其实例提供给OneSignal[OneSignal setNotificationCenterDelegate:yourCustomNotificationCenterDelegateInstance]
请注意,application:didReceiveRemoteNotification:fetchCompletionHandler:当无提示推送通知(内容可用:1)到达时,该函数仍会被调用,但如果UNUserNotificationCenterDelegate使用了用户点击通知,则不会被调用。
另外,在iOS 10.0.X上存在一个问题,该问题application:didReceiveRemoteNotification被称为而不是application:didReceiveRemoteNotification:fetchCompletionHandler:参见:https : //forums.developer.apple.com/thread/54332 ,但是我怀疑这种情况是否适用于您。
| 归档时间: |
|
| 查看次数: |
1834 次 |
| 最近记录: |