我正在尝试以编程方式更改 MFmailComposer 语言。最初,如果我首先选择“英文邮件”按钮 ,MFMailComposer 将以英文打开。现在,如果我选择“阿拉伯语邮件”按钮,那么 MFMailComposer 将以英语打开,而不是阿拉伯语。
这是我的 ViewController 的屏幕截图
那么,如何在不重新启动应用程序的情况下以编程方式更改 MFMailComposer 语言?
这是代码
- (IBAction)showInArabic:(id)sender
{
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"ar", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
[self viewDidUnload];
[self viewDidLoad];
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
if ([mailClass canSendMail])
{
[self displayComposerSheet];
} else {
[self launchMailAppOnDevice];
}
} else {
[self launchMailAppOnDevice];
}
}
- (IBAction)showInEnglish:(id)sender
{
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"en", nil] forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSArray *languages = [NSArray arrayWithObject:@"en"];
[[NSUserDefaults standardUserDefaults] setObject:languages forKey:@"AppleLanguages"];
[self viewDidUnload];
[self viewDidLoad];
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil) {
if ([mailClass canSendMail]) {
[self displayComposerSheet];
} else {
[self launchMailAppOnDevice];
}
} else {
[self launchMailAppOnDevice];
}
}