我如何使用 MailComposer 中示例代码中的调用方法的 getter/setter
我有一个关于 object-c 中的调用方法处理的问题。
我下载了邮件编辑器的苹果示例代码(http:// /developer.apple.com/iphone/library/samplecode/MailComposer/Introduction/Intro.html)。
当用户触摸示例代码中的“撰写邮件”按钮时,
-(void)displayComposerSheet
{
NSLog(@"MCVC displayComposerSheet");
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
将加载 Methode 并显示 mailcomposerview。
用户发送邮件或取消邮件后,将调用以下方法,
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSLog(@"MCVC mailComposeController");
message.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
message.text = @"Result: canceled";
break;
case MFMailComposeResultSaved:
message.text = @"Result: saved";
break;
case MFMailComposeResultSent:
message.text = @"Result: sent";
break;
case MFMailComposeResultFailed:
message.text = @"Result: failed";
break;
default:
message.text = @"Result: not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
您可以在其中实现您的代码。
我现在的问题是如何获取“toRecipients”、“ccRecipients”、“setMessageBody”、“setSubject”等数据?
这可能吗?我不知道如何在 "- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error"-Methode
中使用 getter
如果我忘记了任何信息你需要我会发布它们:)
感谢所有可以帮助我的人:)
i have a question regarding the call-methods handling in object-c.
I downloaded the apple sample code for the mail composer (http://developer.apple.com/iphone/library/samplecode/MailComposer/Introduction/Intro.html).
When the user touches the "Compose Mail"-Button in the sample-code the Methode
-(void)displayComposerSheet
{
NSLog(@"MCVC displayComposerSheet");
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"Hello from California!"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"];
NSArray *ccRecipients = [NSArray arrayWithObjects:@"[email protected]", @"[email protected]", nil];
NSArray *bccRecipients = [NSArray arrayWithObject:@"[email protected]"];
[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];
[picker setBccRecipients:bccRecipients];
// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"png"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"rainy"];
// Fill out the email body text
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
will be loaded and the mailcomposerview appears.
After the user sends the mail or cancels it the following methode will be called
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
NSLog(@"MCVC mailComposeController");
message.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
message.text = @"Result: canceled";
break;
case MFMailComposeResultSaved:
message.text = @"Result: saved";
break;
case MFMailComposeResultSent:
message.text = @"Result: sent";
break;
case MFMailComposeResultFailed:
message.text = @"Result: failed";
break;
default:
message.text = @"Result: not sent";
break;
}
[self dismissModalViewControllerAnimated:YES];
}
in which you can implement your code.
My Question now is how can i get for example the data of "toRecipients", "ccRecipients", "setMessageBody", "setSubject" etc.?
Is this even possible? I dont know how to use the getter in the "- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error"-Methode
If i forgot any informations you need i will post them :)
Thanks for everyone who can help me out :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 Apple API:
重要提示:邮件撰写界面本身不可自定义,并且您的应用程序不得对其进行修改。此外,在呈现界面后,您的应用程序不允许对电子邮件内容进行进一步的更改。用户仍然可以使用界面编辑内容,但程序更改将被忽略。因此,您必须在呈现界面之前设置内容字段的值。
看看这个,并尝试了适合 didFinishWithResult: 方法中的 ivars 的各种名称,似乎不可能从预构建的 MFMailComposeViewController 中获取此信息,
您可以子类化此类或推出自己的类来获取功能..但这似乎是唯一的方法。
From the Apple API:
Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.
Looking at this, and also trying out various names that would be appropriate for the ivars in the didFinishWithResult: method, it seems it is NOT possible to get this information from the prebuilt MFMailComposeViewController
you could subclass this class or roll your own to get the functionality..but that seems to be the only way to do it.