gpt4 book ai didi

objective-c - 邮件集成取消

转载 作者:搜寻专家 更新时间:2023-10-30 20:06:25 25 4
gpt4 key购买 nike

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

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

你们能不能帮忙把它扔...

@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

这是我的实现文件

最佳答案

您必须将您的 Controller 设置为 MFMailComposeViewController 的委托(delegate)

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

而且您必须实现以下委托(delegate)方法。就是这样。

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

关于objective-c - 邮件集成取消,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11409380/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com