次のコードを使用してメールを送信します。
- (IBAction)sendMailPressed:(id)sender
{
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:self.strMailSubject];
// Attach pdf to the email
NSURL *urlToLoad = [[NSBundle mainBundle] URLForResource:self.strSorce withExtension:self.strExtention];
NSData *myData = [NSData dataWithContentsOfURL:urlToLoad];
[picker addAttachmentData:myData mimeType:@"application/pdf" fileName:[NSString stringWithFormat:@"%@.%@", self.strSorce, self.strExtention]];
// [self presentModalViewController:picker animated:YES];
[[Singleton sharedInstance] pushModalViewController:picker whereCurrentController:self animated:YES];
[picker release];
}
// Dismisses the email composition interface when users tap Cancel or Send. Proceeds to update the message field with the result of the operation.
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSaved:
break;
case MFMailComposeResultSent:
break;
case MFMailComposeResultFailed:
break;
default:
break;
}
[[Singleton sharedInstance] popModalViewControllerAnimated:YES];
}
// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{
NSString *recipients = [NSString stringWithFormat:@"mailto:&subject=%@", self.strMailSubject];
NSString *email = [NSString stringWithFormat:@"%@", recipients];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
そして、私はこの見解を得る:
しかし、私はこのビューが必要です(画像ではなく、文字列からのみに注意してください)。
From文字列を表示する方法がわかりません