I am opening an email sheet to send a file. It works great except that I can’t go back to my app.
When I hit cancel button, it ask if to delete or save draft, and stay there. It doesn’t go back to app page.
code:
//send email log-------------------------
NSLog(@"mail");
[[CCDirector sharedDirector] pause];
picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
//Fill in the email as you see fit
NSArray *toRecipients = [NSArray arrayWithObject:@"name@gmail.com"];
[picker setToRecipients:toRecipients];
NSArray *paths2 = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dataPath = [[paths2 objectAtIndex:0] stringByAppendingPathComponent:@"Test.txt"];
NSData *data = [NSData dataWithContentsOfFile:dataPath];
[picker addAttachmentData:data mimeType:@"text/txt" fileName:@"Test.txt"];
NSString *emailBody = @"Test ";
[picker setMessageBody:emailBody isHTML:NO];
[picker setSubject:@"hardware test ## "];
//display the view
[[[CCDirector sharedDirector] openGLView] addSubview:picker.view];
[[CCDirector sharedDirector] stopAnimation];
EDIT:
I have added the function suggested in the answer right here, he calls the function when I hit cancel, but it stays in that sheet.
I have to say that I am using a cclayer (cocos2d) so the layer is defined with :
@interface HelloWorldLayer : CCLayer< MFMailComposeViewControllerDelegate>
Any other suggestion ?
Thanks a lot.
You have to implement the delegate method
and dismiss the view controller in there:
UPDATE: