0

Hi i i have a local push notification problem. I implemented in-app language change function in my app. and i have to restart the app after changed for reflect changes all part of my app. so i use abort() method. before abort app i scheduled notification like this

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

i want to user come back to app by touching alert but push message didn't come at all the time. sometimes it was came and doesn't work again. please help me if you know something about this issue.

  • there is a way to change your App-Language without restart your application, which I think is better using `NSLocalizedStringFromTable` instead of `NSLocalizedString` by the way your code is in Objective-C but your question tag is swift??? I can provide a basic example of how can be done if you want – Reinier Melian Feb 12 '18 at 08:13
  • yeah i know i use CusomLocalizedString in this link http://createdineden.com/blog/post/language-changer-in-app-language-selection-in-ios/ but some part in my app difficult to change while running Restart the app is more clean than just change while running. i want to implemet like instagram in-app change function – San Gyeol Kang Feb 12 '18 at 08:25

2 Answers2

0

Call abort() in completion handler:

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

But anyway, calling abort() isn't good practice.

Ilya Kharabet
  • 4,203
  • 3
  • 15
  • 29
  • How to execute some code after receiving the push notification. Like replying back to the server with some data after receiving the push notification on the killed ios app via FCM or APNS? – Shubham1164 Feb 11 '19 at 17:00
0

You shall not exit app (someone already posted it here https://stackoverflow.com/a/356342/6429711 and I believe Apple have it somewhere in guidelines).

You can change language without quitting app. When you generate app multiple bundles are generated. You can change localisation from separate bundles then.

Example:

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

Where currentLanguageBundle is bundle based on the currently selected language.

Adamsor
  • 730
  • 1
  • 6
  • 14