Я пытался внедрить 'mail composer' (пример кода из dev) в мои приложения.Они очень жестко запрограммированы в примере кода.Например: отправлено получателю - first@example.com.Я хочу оставить это поле пустым, как @""
, однако перед адресом электронной почты автоматически ставится запятая.У меня также есть другая проблема, основанная на readme.txt Apple DEV, launchMailAppOnDevice
будет запущен, если displayComposerSheet
не удалось.Стоит ли заменить все жестко закодированные в launchMailAppOnDevice
и как это сделать?Пожалуйста, сообщите.
-(IBAction)showPicker:(id)sender
{
// This sample can run on devices running iPhone OS 2.0 or later
// The MFMailComposeViewController class is only available in iPhone OS 3.0 or later.
// So, we must verify the existence of the above class and provide a workaround for devices running
// earlier versions of the iPhone OS.
// We display an email composition interface if MFMailComposeViewController exists and the device can send emails.
// We launch the Mail application on the device, otherwise.
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
}
// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Visit my new apps in app store!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"];
[picker setToRecipients:toRecipients];
//Replace the email body with the content from my textview
[picker setMessageBody:TextView.text isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{
NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";
NSString *body = @"&body=It is raining in sunny California!";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}