我正在从节点服务器向iPhone和Android发送推送通知。它已成功发送到APNS / GCM并成功接收到移动设备的通知。但是,在iPhone 6中,推送通知在收到通知后第一次没有收到通知。它发生在以下阶段:
提前致谢..
答案 0 :(得分:0)
Apple在Local and Push Notification Programming Guide和Troubleshooting Push Notifications
中说发送通知是“尽力而为”,不能保证。它是 不打算向您的应用程序提供数据,只是为了通知用户 有新数据可供使用。
<强>更新强>
问题是Apple在无法处理邮件时关闭连接。因此,更新了Node推送通知server.js中的代码,如下所示,它完美运行:
var connectCallback = function (err) {
// gracefully handle auth problems
if (err && err.name === 'GatewayAuthorizationError') {
console.log('Authentication Error: %s', err.message);
process.exit(1);
}
// handle any other err (not likely)
else if (err) {
throw err;
}
// it worked!
var env = agent.enabled('sandbox')
? 'sandbox'
: 'production';
console.log('apnagent [%s] gateway connected', env);
};
agent.connect(connectCallback);
setInterval(function(){
agent.close(function(param1){
agent.connect(connectCallback);
});
}, 20 * 60 * 1000);
答案 1 :(得分:0)
我遇到了同样的问题,我通过以下方式解决了这个问题: -
在didFinishLaunchingWithOptions方法中写这个
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
[[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
[[UIApplication sharedApplication] registerForRemoteNotifications];
} else {
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge];
}
它将触发用户的权限警报。 如果他允许,则以成功方式发送设备令牌: -
#pragma PushNotification delegation
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
NSString *device = [deviceToken description];
device = [device stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"<>"]];
device = [device stringByReplacingOccurrencesOfString:@" " withString:@""];
NSLog(@"My deviceToken is: %@", device);
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:device forKey:@"deviceToken"];
// Now send device token to server
}