应用程序杀死后,iOS本地推动通知



嗨,我有一个本地推送通知问题。我在应用程序中实现了应用内语言更改功能。更改后,我必须重新启动该应用程序,以反映更改应用程序的所有部分。因此,我使用Abort((方法。在流产应用程序之前,我安排了这样的通知

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();

我想通过触摸警报来返回应用程序但是,推动消息并非总是如此。有时候来了并且不再工作。如果您对此问题有所了解,请帮助我。

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

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

但是无论如何,打电话给abort()不是很好的做法。

您不得退出应用程序(有人已经在此处发布了它https://stackoverflow.com/a/356342/6429711,我相信苹果在指导方针中都有它。

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

示例:

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

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

最新更新