应用程序被杀后ios本地推送通知

时间:2018-02-12 08:01:17

标签: ios push-notification

您好我有本地推送通知问题。 我在我的应用程序中实现了应用程序内语言更改功能。 并且我必须在更改后重新启动应用程序以反映我的应用程序的所有部分的更改。所以我使用abort()方法。 在中止app之前我安排了这样的通知

UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.title = [NSString localizedUserNotificationStringForKey:@"Hello!" arguments:nil];
content.body = [NSString localizedUserNotificationStringForKey:@"Languaged changed. Touch to restart." arguments:nil];
content.sound = [UNNotificationSound defaultSound];

// Deliver the notification in five seconds.
UNTimeIntervalNotificationTrigger* trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:3 repeats:NO];
UNNotificationRequest* request = [UNNotificationRequest requestWithIdentifier:@"FiveSecond" content:content trigger:trigger];


// Schedule the notification.
UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
[center addNotificationRequest:request withCompletionHandler:nil];

abort();

我希望用户通过触摸提醒返回应用 但是推送消息并没有随时出现。有时它来了 并且不再工作。 如果你对这个问题有所了解,请帮助我。

2 个答案:

答案 0 :(得分:0)

在完成处理程序中调用abort()

[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
    abort();
}];

但无论如何,调用abort()并不是一种好习惯。

答案 1 :(得分:0)

你不应该退出应用程序(某人已在此处发布了https://stackoverflow.com/a/356342/6429711,我相信Apple已将其纳入指南中。)

您可以在不退出应用的情况下更改语言。生成应用程序时会生成多个包。您可以从单独的包中更改本地化。

示例:

extension String
{
    // Get selected language
    var localized: String {
    return NSLocalizedString(self, tableName: nil, bundle: currentLanguageBundle, value: "", comment: "")
    }
}

其中currentLanguageBundle是基于当前所选语言的捆绑包。

相关问题