静音推送通知在后台模式下无法在iOS7上运行

编程入门 行业动态 更新时间:2024-10-25 10:29:40
本文介绍了静音推送通知在后台模式下无法在iOS7上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有这种奇怪的情况,我的应用支持iOS7及以上版本。它做了什么,通过使用静默通知启用远程通知。

I have this weird situation, my app support iOS7 and above. what it does, it's enabled Remote notifications by using silent notifications.

我知道上面的iOS7和iOS8有不同的逻辑来处理通知。我这样做了:

I know that iOS7 and iOS8 above has different logic to handle notification. I did this :

if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; [[UIApplication sharedApplication] registerForRemoteNotifications]; } else { [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; }

这里的通知收到

{ aps = { "content-available" = 1; }; }

所以它的作用是,应用程序接收静默通知,以及然后设置localNotification,见下文:

So what it does is, app receive silent notification, and then set localNotification, see below :

UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5]; notification.soundName = UILocalNotificationDefaultSoundName; notification.alertBody = @"testing"; notification.timeZone = [NSTimeZone defaultTimeZone]; [[UIApplication sharedApplication] scheduleLocalNotification:notification];

所有它都适用于iOS8和iOS9的后台模式和前台模式。当应用程序位于前台时,它将触发 didReceiveLocalNotification 。

All it works in iOS8 and iOS9 in background mode and foreground mode. When app is in foreground, it will trigger didReceiveLocalNotification.

但是当我在iOS7中测试时,如果应用程序处于后台模式,它将无效。我试图找出这是如何发生的,而其他操作系统工作正常。我在应用程序打开时进行了测试,它确实收到了推送通知,并且 didReceiveLocalNotification 被触发。但是当进入后台时,没有任何事情发生(没有本地推送通知)。

But when I was testing in iOS7, it doesn't work if the app is in background mode. I'm trying to figure out how this happen, while other OS working fine. I did test while app is open, it did receive push notification, and didReceiveLocalNotification get triggered. but when goes to background, nothing happen (no local push notification).

推荐答案

正如本文所述,aps需要包含优先级,以便在iOS7中工作。

As pointed in this tread, aps need to include priority in order to work in iOS7.

aps = { badge = 7; "content-available" = 1; priority = 5; };

检查: stackoverflow/a/23917593/554740

更多推荐

静音推送通知在后台模式下无法在iOS7上运行

本文发布于:2023-11-27 10:10:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637641.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:静音   后台   通知   模式下

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!