【问题标题】:local notifications ios 11 in background本地通知 ios 11 在后台
【发布时间】:2017-09-24 06:03:10
【问题描述】:

我在 cordova 中准备了 iOS 应用程序,我使用原始的 Cordova 插件进行本地通知。我在通知中心安排了大约 90 个本地通知。它在 iOS 10 上运行,但在 iOS 11 上并非总是如此,也不是在所有设备上。

例如,在我的手机上,我可以看到所有通知 - 前台和后台。

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

这是 iOS 11 的错误吗?

更新 - 已解决

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

【问题讨论】:

  • 我遇到了完全相同的问题,但我还没有找到解决方案!
  • 在 iOS 10 上我遇到了同样的问题,正在尝试寻找解决方案。

标签: objective-c cordova ios11


【解决方案1】:

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

[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];

}

【讨论】:

  • 你不应该使用 UNUserNotification 框架吗?
  • 也许我不明白你,我使用 UIKit 框架,当后台应用程序在屏幕上显示消息时,此代码运行 IOS 11。
  • 但由于它已被弃用,你永远不知道 Apple 何时会放弃对它的支持。
猜你喜欢
  • 2014-12-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多