3
- (void) showMail
{
    [[CCDirector sharedDirector] pause];
    NSString*myemail=@"sirano0629@me.com";
    NSArray*email=[[NSArray alloc]initWithObjects:myemail, nil];
    if([MFMailComposeViewController canSendMail])
    {
        mail = [[MFMailComposeViewController alloc] init];
        [mail setSubject:[NSString stringWithFormat:@"건의 및 문의"]];
        [mail setToRecipients:email];
        [self presentModalViewController:mail animated:YES];
        [mail release];
    }
}



- (void)mailComposeController:(MFMailComposeViewController *)controller                   didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
    [mail dismissModalViewControllerAnimated:YES];
    mail.view.hidden=YES;
    [[CCDirector sharedDirector] resume];
    //return to previous scene
    [[CCDirector sharedDirector] replaceScene:[HelloWorldLayer scene]];
}

这是我在应用程序中进行电子邮件集成的代码。首先打开电子邮件视图是成功的,但是在我按下发送或取消后,视图并没有消失......

各位大佬能帮忙扔一下吗...

@class SingletonClass;

@interface GameCenterView : UIViewController     <GKLeaderboardViewControllerDelegate,MFMailComposeViewControllerDelegate>
{
SingletonClass * singleCurrentAverage;
MFMailComposeViewController*mail;
NSInteger score;
}


-(void)showLeaderboard;
-(void)showTweetForUnder;
-(void)showTweetForPost;
-(void)showMail;
@end

我使用的头文件

#import "GameCenterView.h"
#import "GameCenterUtil.h"
#import "HelloWorldLayer.h"
#import "SingletonClass.h"
#import "AppDelegate.h"
#import <MessageUI/MessageUI.h>

@interface GameCenterView ()

@end

@implementation GameCenterView


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
    if ([GameCenterUtil isGameCenterAPIAvailable]) {
        [GameCenterUtil authenticateLocalPlayer];
    }else {
        NSLog(@"this device do not support GameCenter");
    }

}
return self;
}
-(void)showLeaderboard
{
self.view.hidden=NO;

GKLeaderboardViewController * leaderboardController = [[[GKLeaderboardViewController alloc]init]autorelease];
if (leaderboardController!=nil) {
    leaderboardController.leaderboardDelegate=self;

    [self presentModalViewController:leaderboardController animated:YES];

}
}
-(void)showTweetForUnder
{
singleCurrentAverage=[SingletonClass sharedGameStateInstance];
score=[singleCurrentAverage currentAverage];
if([TWTweetComposeViewController canSendTweet]) {
    TWTweetComposeViewController*tweet=[[TWTweetComposeViewController alloc]init];
    [tweet setInitialText:[NSString stringWithFormat:@"대학교 점수 :%d from 성적UP iOS. \n 친구들에게 하고싶은 말을 적으세요.",score]];
    NSURL*url=[NSURL URLWithString:@"http://www.facebook.com/avoidpoo"];
    [tweet addURL:url];
    UIImage *image=[UIImage imageNamed:@"Icon-72.png"];
    [tweet addImage:image];
    [self presentModalViewController:tweet animated:YES];
} 
}

-(void)showTweetForPost
{
singleCurrentAverage=[SingletonClass sharedGameStateInstance];
score=[singleCurrentAverage currentAverage];
if ([TWTweetComposeViewController canSendTweet]) {
    TWTweetComposeViewController*tweet=[[TWTweetComposeViewController alloc]init];
    [tweet setInitialText:[NSString stringWithFormat:@"대학원 점수: %d from 성적Up iOS. \n 친구들에게 하고 싶은 말을 적으세요.",score]];
    NSURL*url=[NSURL URLWithString:@"http://www.facebook.com/avoidpoo"];
    [tweet addURL:url];
    UIImage *image=[UIImage imageNamed:@"Icon-72.png"];
    [tweet addImage:image];
    [self presentModalViewController:tweet animated:YES];

}
}
- (void) showMail
{
mail.mailComposeDelegate=self;
NSString*myemail=@"sirano0629@me.com";
NSArray*email=[[NSArray alloc]initWithObjects:myemail, nil];
if([MFMailComposeViewController canSendMail]) {
    mail = [[MFMailComposeViewController alloc] init];
    [mail setSubject:[NSString stringWithFormat:@"건의 및 문의"]];
    [mail setToRecipients:email];
    [self presentModalViewController:mail animated:YES];
    [mail release];
}
} // From Here You can Dismisses the email composition interface when users tap Cancel or Send. 
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
{   
// Notifies users about errors associated with the interface
switch (result)
 {
    case MFMailComposeResultCancelled:
        NSLog (@"Result: canceled");
        break;
    case MFMailComposeResultSaved:
        NSLog (@"Result: saved");
        break;
    case MFMailComposeResultSent:
        NSLog (@"Result: sent");
        break;
    case MFMailComposeResultFailed:
        NSLog (@"Result: failed");
        break;
    default:
        NSLog (@"Result: not sent");
        break;
}
[self dismissModalViewControllerAnimated:YES];
}
-(void) leaderboardViewControllerDidFinish:(GKLeaderboardViewController *)viewController
{
[self dismissModalViewControllerAnimated:YES];

self.view.hidden =YES;

}


-  (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

这是我的实现文件

4

1 回答 1

4

您必须将您的控制器设置为 MFMailComposeViewController 的委托,例如

if([MFMailComposeViewController canSendMail]) {
    mail = [[MFMailComposeViewController alloc] init];

    mail.mailComposeDelegate = self; //<-- Add this line

    [mail setSubject:[NSString stringWithFormat:@"건의 및 문의"]];
    [mail setToRecipients:email];
    [self presentModalViewController:mail animated:YES];
    [mail release];
}

而且你必须实现以下委托方法。就是这样。

   // From Here You can Dismisses the email composition interface when users tap Cancel or Send. 
    - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error 
    {   
    // Notifies users about errors associated with the interface
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog (@"Result: canceled");
            break;
        case MFMailComposeResultSaved:
            NSLog (@"Result: saved");
            break;
        case MFMailComposeResultSent:
            NSLog (@"Result: sent");
            break;
        case MFMailComposeResultFailed:
            NSLog (@"Result: failed");
            break;
        default:
            NSLog (@"Result: not sent");
            break;
    }
    [self dismissModalViewControllerAnimated:YES];
    }
于 2012-07-10T08:56:28.940 回答