Ios UILocalNotification alertBody和操作未本地化
我目前正在尝试使用本地化消息和操作安排本地通知。但是,即使我更改了iPhone语言,下一个通知仍然使用以前的语言:( 以下代码用于计划本地notif,并在用户注册(didRegisterUserNotificationSettings:)或语言(存储在NSUserDefault中)更改后调用:Ios UILocalNotification alertBody和操作未本地化,ios,objective-c,localization,uilocalnotification,Ios,Objective C,Localization,Uilocalnotification,我目前正在尝试使用本地化消息和操作安排本地通知。但是,即使我更改了iPhone语言,下一个通知仍然使用以前的语言:( 以下代码用于计划本地notif,并在用户注册(didRegisterUserNotificationSettings:)或语言(存储在NSUserDefault中)更改后调用: - (void)scheduleNotifForDate:(NSDate*)date andHour:(NSString*)hour andMessage:(NSString*)keyMessageLoc
- (void)scheduleNotifForDate:(NSDate*)date andHour:(NSString*)hour andMessage:(NSString*)keyMessageLocalized repeatedDayly:(BOOL)repeated withAction:(NSString*)keyActionLocalized andUserInfos:(NSDictionary*)userInfos {
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd/MM/yyyy"];
NSString* dateStr = [NSString stringWithFormat:@"%@ %@", [dateFormatter stringFromDate:date], hour];
NSDateFormatter *dateTimeFormatter = [[NSDateFormatter alloc] init];
[dateTimeFormatter setDateFormat:@"dd/MM/yyyy HH:mm:ss"];
Class cls = NSClassFromString(@"UILocalNotification");
if (cls != nil) {
UILocalNotification *notif = [[cls alloc] init];
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.fireDate = [dateTimeFormatter dateFromString:dateStr];
notif.alertBody = NSLocalizedString(keyMessageLocalized, nil);
notif.alertAction = NSLocalizedString(keyActionLocalized, nil);
notif.soundName = UILocalNotificationDefaultSoundName;
notif.repeatInterval = repeated ? NSCalendarUnitDay : NSCalendarUnitWeekday;
notif.userInfo = userInfos;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
}
}
我是否错过了本地化消息?
我有一个解决办法,可以取消本地notif并使用相同的参数重新安排,一旦重新安排,它就可以完美地工作。但这意味着,如果用户在更改语言后不打开应用程序,它仍将以以前的语言显示
谢谢和问候,
塞巴斯蒂安。用这个:
notif.alertTitle = NSLocalizedString(@"location", @"location");
notif.alertBody = NSLocalizedString(@"location", @"location");
你能进一步解释一下吗?有没有本地location.strings?