2012-05-12 50 views
0

我打開電子郵件表發送文件。除了我不能回到我的應用程序,它工作得很好。電子表格無法取消?

當我擊取消按鈕,就詢問是否刪除或保存草稿,並呆在那裏。它不會回到應用程序頁面。

代碼:

//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:@"[email protected]"]; 
    [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]; 

編輯:

我加入的回答表明這裏的功能,他叫我擊球的時候取消該功能,但它停留在那個片。 我不得不說,我使用的是cclayer(cocos2d的),所以層與定義:

@interface HelloWorldLayer : CCLayer< MFMailComposeViewControllerDelegate> 

任何其他建議?

非常感謝。

回答

4

您必須實現委託方法

- (void)mailComposeController:(MFMailComposeViewController*)controller 
     didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 

並關閉在那裏的視圖控制器:

[picker dismissViewControllerAnimated:YES completion:^{}]; 

UPDATE:

- (void)mailComposeController:(MFMailComposeViewController*)controller 
      didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
    [picker dismissViewControllerAnimated:YES completion:^{}]; 
} 
+0

感謝,但他不接受 「resault」我錯過了什麼? – user1280535

+0

確定我已經把它改爲:(MFMailComposeViewController *)控制器didFinishWithResult:(MFMailComposeResult)的結果,但它仍然無法正常工作,我打取消,然後我不能再,但打它它留在這片。任何幫助? – user1280535

+0

你是什麼意思「他不接受結果」? – DrummerB