我试图从Xcode 6在iOS 8中打开邮箱镇静,但出现了一个错误.如果我try 使用Xcode 5,同样的代码也可以正常工作.后来,我从apple developer portal下载了一个示例代码:

https://developer.apple.com/library/content/samplecode/MessageComposer/Introduction/Intro.html

但结果是一样的.在优化Xcode 6的代码时,我是否缺少了一些东西或设置

以下是代码:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];

picker.mailComposeDelegate = self;

[picker setSubject:@"Hello from California!"];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];  
[picker setBccRecipients:bccRecipients];

// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"rainy" ofType:@"jpg"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"rainy"];

// Fill out the email body text
NSString *emailBody = @"It is raining in sunny California!";
[picker setMessageBody:emailBody isHTML:NO];

[self presentViewController:picker animated:YES completion:NULL];

给代表发邮箱

self.feedbackMsg.hidden = NO;
// Notifies users about errors associated with the interface
switch (result)
{
    case MFMailComposeResultCancelled:
        self.feedbackMsg.text = @"Result: Mail sending canceled";
        break;
    case MFMailComposeResultSaved:
        self.feedbackMsg.text = @"Result: Mail saved";
        break;
    case MFMailComposeResultSent:
        self.feedbackMsg.text = @"Result: Mail sent";
        break;
    case MFMailComposeResultFailed:
        self.feedbackMsg.text = @"Result: Mail sending failed";
        break;
    default:
        self.feedbackMsg.text = @"Result: Mail not sent";
        break;
}

[self dismissViewControllerAnimated:YES completion:NULL];

结果:

邮箱镇静委托自动消失,结果为0,

错误代码:MessageComposer[10993:196902]

2014-09-17 22:04:22.538 MessageComposer[10993:205761]

推荐答案

从表面上看,这只是一个模拟器的问题.(iOS 8模拟器)

如果有人遇到这个问题,就在真正的设备上测试一下.

Objective-c相关问答推荐

在 iOS 7 上,如果最终包含在选项卡栏控制器中,则使用工具栏推送控制器会留下不可用空间的间隙

将谷歌 map 添加为子视图会使 iOS 应用程序因 exc_bad 崩溃

将长按手势和拖动手势结合在一起

UITableView 无限滚动

iOS 正确使用 @weakify(self) 和 @strongify(self)

UIDatePicker,根据今天的日期设置最大和最小日期

Facebook 的 UIActivityViewController 不显示默认文本

Facebook 添加测试用户和管理员是:(待定),这是什么意思?

动态转发: suppress Incomplete Implementation 警告

Objective-C:如何使用 BOOL 类型的参数调用 performSelector?

如何测试推送通知在我的应用程序中是否有效

dyld:找不到符号:try 运行 iOS 应用程序时的 _NSURLAuthenticationMethodClientCertificate

反转 NSString 文本

如何对包含数字的 NSMutable 数组进行排序?

UIWebView didFinishLoading 多次触发

UILabel 根据要显示的文本自动调整大小

在 UITextField 文本上投影

如何在 iOS 中计算 SHA-2(最好是 SHA 256 或 SHA 512)哈希?

UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效?

如何将 printf 与 NSString 一起使用