2
我試圖使用MessageUI框架以編程方式發送郵件。這是我在MyScene.m中的。當我調用該方法時,將打開一個郵件窗口。但是,當我取消郵件或發送郵件時,它不會返回到MyScene。在Sprite Kit中以編程方式發送郵件
#import <MessageUI/MessageUI.h>
-(void)sendMail
{
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:@"Subject"];
[mc setMessageBody:@"Hello!" isHTML:NO];
[mc setToRecipients:[NSArray arrayWithObject:@"[email protected]"]];
// Present mail view controller on screen
[self.view.window.rootViewController presentViewController:mc animated:YES completion:NULL];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result)
{
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved");
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail sent failure: %@", [error localizedDescription]);
break;
default:
break;
}
// Close the Mail Interface
[self.view.window.rootViewController dismissViewControllerAnimated:YES completion:NULL];
}
這也不起作用。我怎樣才能從UIViewController呈現它? –
是 - (void)mailComposeController:(MFMailComposeViewController *)控制器didFinishWithResult:(MFMailComposeResult)結果錯誤:(NSError *)錯誤被觸發? –
不,事實並非如此。我 –