[英]Push notification does not appear if app is in background on iOS 9
I'm having an issue with push notifications and it affects only my devices running iOS 9:我遇到了推送通知问题,它只影响我运行 iOS 9 的设备:
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];
}
application:didReceiveRemoteNotification:
).显示通知(由application:didReceiveRemoteNotification:
触发)。Has anything changed on iOS 9? iOS 9 有什么变化吗? How can I make the push notifications display also on iOS 9, even if the app is not active?即使应用程序未处于活动状态,如何使推送通知也显示在 iOS 9 上? I don't want to use notifications to fetch any content in background, I just need to display a message.我不想使用通知在后台获取任何内容,我只需要显示一条消息。
In the end, I had to do two things that made it work for me:最后,我必须做两件事才能让它对我有用:
It seems you are OK.看来你没事。 This is my code, i get notification in iOS 9.0 also.这是我的代码,我也在 iOS 9.0 中收到通知。
-(void)registarPushNotification:(UIApplication*)application
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
{
UIUserNotificationType types = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[application registerUserNotificationSettings:mySettings];
[application registerForRemoteNotifications];
}
else
{
[application registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)];
}
}
I think that the user has to tap the notification to bring the app to the foreground and then application(_:didReceiveRemoteNotification:)
will be called.我认为用户必须点击通知才能将应用程序带到前台,然后application(_:didReceiveRemoteNotification:)
将被调用。
See here: https://www.raywenderlich.com/123862/push-notifications-tutorial请参阅此处: https : //www.raywenderlich.com/123862/push-notifications-tutorial
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.