静音推送通知在后台模式下无法在iOS7上运行 [英] Silent push notification doesn't work on iOS7 in background mode

查看:183
本文介绍了静音推送通知在后台模式下无法在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;
    }; 

检查: https://stackoverflow.com/a/23917593/554740

这篇关于静音推送通知在后台模式下无法在iOS7上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆