localisation dans les notifications iOS?
-
25-09-2019 - |
Question
J'ai mon application en cours d'exécution bien et il utilise les notifications locales.
J'ai décidé d'internationaliser l'application maintenant et ont tout fonctionne très bien, sauf les notifications qui ont été définies sur une langue avant de changer la langue de l'appareil.
Je alimenter les messages dans la notification d'un tableau qui contient des chaînes localisées, donc je pensais que lorsque l'utilisateur change la langue du dispositif de la chaîne dans la notification changerait aussi, mais je me trompais.
La meilleure façon d'aborder ce problème? Au cas où le texte de mon NSString également NSLocalizationString?
Mon code de notification:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
return;
localNotif.fireDate = [alertTimes objectAtIndex:i];
localNotif.timeZone = [NSTimeZone defaultTimeZone];
NSString *text = [alertText objectAtIndex:i];
// Notification details
localNotif.alertBody = text;
// Set the action button
localNotif.alertAction = @"View";
localNotif.soundName = UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber = 1;
// Specify custom data for the notification
NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
localNotif.userInfo = infoDict;
// Schedule the notification
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
[localNotif release];
La solution
Si mon texte NSString également NSLocalizationString?
Oui, je le ferais.
Remplacer [alertTimes objectAtIndex:i]
avec NSLocalizedString(@"alertTimes",[alertTimes objectAtIndex:i])
. Je suppose que vous stocker des chaînes dans le tableau de alertTimes
qui correspondent à votre chaîne localisée.