电子邮件解决iOS 8
我试图从Xcode 6中打开iOS 8中的电子邮件镇静,但得到一个错误。 如果我从Xcode 5尝试,相同的代码工作正常。后来我从苹果开发者门户网站下载了一个示例代码:
https://developer.apple.com/library/content/samplecode/MessageComposer/Introduction/Intro.html
但结果是一样的。 有没有什么,或者一些设置,我错过了优化Xcode 6的代码
这里是代码:在我的button行动
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,即MFMailComposeResultCancelled
错误代码:MessageComposer [10993:196902] viewServiceDidTerminateWithError:Error Domain = _UIViewServiceInterfaceErrorDomain Code = 3“操作无法完成(_UIViewServiceInterfaceErrorDomain错误3.)”UserInfo = 0x7b93f7e0 {消息=服务连接中断}
和
2014-09-17 22:04:22.538 MessageComposer [10993:205761]超时等待来自com.apple.MailCompositionService
从外观上看,这是一个模拟器的问题。 (iOS 8模拟器)globalMailer方法在设备上正常工作。
如果有人遇到这个问题,只需在真实的设备上进行testing。