51

I'm trying to open email composure in iOS 8 from Xcode 6, but getting an error. The same code is working fine if I'm trying from Xcode 5. Later I downloaded a sample code from apple developer portal:

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

But the result is same. Is there something, or some setting, I'm missing to optimise the code for Xcode 6

Here is the code: in my button action

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];

email delegate

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];

result:

email composure delegate disappearing automatically with result 0, i.e., MFMailComposeResultCancelled

with error codes : MessageComposer[10993:196902] viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" UserInfo=0x7b93f7e0 {Message=Service Connection Interrupted}

and

2014-09-17 22:04:22.538 MessageComposer[10993:205761] timed out waiting for fence barrier from com.apple.MailCompositionService

Cœur
  • 37,241
  • 25
  • 195
  • 267
Chahal
  • 995
  • 2
  • 14
  • 24
  • 2
    What's the error? Show the relevant code in your question. – rmaddy Sep 17 '14 at 16:22
  • Again, what is the error? Which line? – rmaddy Sep 17 '14 at 16:29
  • See this question: http://stackoverflow.com/questions/25604552/i-have-real-misunderstanding-with-mfmailcomposeviewcontroller-in-swift-ios8-in – hoiberg Sep 17 '14 at 16:29
  • 1
    @hoiberg42 you are correct, that are the error codes I am getting after the email composure controller dismissing itself. – Chahal Sep 17 '14 at 16:36
  • I'm having the exact same issue, tried the globalMailer approach but it still does it. Mail view controller appears, gets stuck, and dismisses automatically. :/ – Vrasidas Sep 18 '14 at 09:53
  • 2
    I just tested on a iOS 8 device and it seems that the globalMailer works. So it must be a Simulator issue... – Vrasidas Sep 18 '14 at 10:15
  • @Vrasidas: yes this is true, its just the simulator issue, If you post the answer i'll accept it. – Chahal Sep 23 '14 at 15:38

1 Answers1

102

By the looks of it, this is a simulator-only issue. (iOS 8 simulator) The globalMailer approach works ok on devices.

If anyone encounters this problem, just test on a real device.

Vrasidas
  • 2,085
  • 1
  • 17
  • 23