本地通知ios 11在后台

时间:2017-09-24 06:03:10

标签: objective-c cordova ios11

我在cordova中准备了iOS应用程序,我使用原始Cordova插件进行本地通知。我在通知中心安排了大约90个本地通知。它在iOS 10上工作,但在iOS 11上并不总是在每台设备上都有。

例如,在我的手机上,我会看到所有通知 - 前景和背景。

在其他手机上,我只在前台(应用内部)看到通知,而不是在后台。

这是iOS 11的错误吗?

更新 - 已解决

用于本地通知的Cordova插件只能安排64个本地通知(如iOS文档限制)。因此,我需要使用队列为64个当前本地通知和数据库编写本机模块,以便在限制之后设置下一个本地通知。

1 个答案:

答案 0 :(得分:0)

IOS 11尝试在 - (void)applicationDidEnterBackground :( UIApplication *)应用程序中使用它

[self performSelectorInBackground:@selector(showNotical:) withObject:@"Open InBack"];

方法

- (void) showNotical:(NSString*)msg <br>
{

    UIApplication *application = [UIApplication sharedApplication];

    if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
    {
            //UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
        [application registerUserNotificationSettings:settings];

    }
    else // iOS 7 or earlier
    {
            //UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [application registerForRemoteNotificationTypes:myTypes];
    }

    UILocalNotification* localNotification = [[UILocalNotification alloc] init];
        //    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
    localNotification.alertAction = @"test";
    localNotification.alertBody = [NSString stringWithFormat:@"%@",msg];
    localNotification.soundName = UILocalNotificationDefaultSoundName; // den den den
    localNotification.repeatInterval = 7;
        //[UIApplication sharedApplication].applicationIconBadgeNumber=1;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

}