3

我试图在我的应用程序中插入一个邮件工具....我的应用程序是基于 cocos2d 引擎的

工具栏(在顶部->取消,发送...)是可见的,但我看不到 mfMailComposerViewController 视图的其他部分:-(

代码:

-(void)displayComposerSheet {   
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"my message"];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"first@example.com"]; 
NSArray *ccRecipients = [NSArray arrayWithObjects:@"second@example.com", @"third@example.com", nil]; 
NSArray *bccRecipients = [NSArray arrayWithObject:@"fourth@example.com"]; 

[picker setToRecipients:toRecipients];
[picker setCcRecipients:ccRecipients];  
[picker setBccRecipients:bccRecipients];

// Attach an image to the email
UIImage *screenshot = [[Director sharedDirector] screenShotUIImage];
NSData *myData = UIImagePNGRepresentation(screenshot);
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"AdMotiv"]; 

// Fill out the email body text
NSString *emailBody = @"test";
[picker setMessageBody:emailBody isHTML:NO];
[[picker view] setFrame:CGRectMake(0.0f,0.0f,320.0f, 480.0f)];

[[picker view] setTransform:CGAffineTransformIdentity];
[[picker view] setBounds:CGRectMake(0.0f,0.0f,320.0f, 480.0f)];
//[[[VariableStore sharedInstance] parentView] setTransform: CGAffineTransformIdentity];
//[[[VariableStore sharedInstance] parentView] setBounds : CGRectMake(0.0f, 0.0f, 480.0f, 320.0f)];

UITextField *textfeld = [[UITextField alloc] initWithFrame:CGRectMake(50.0f, 50.0f, 100.0f, 100.0f)];
[[picker view] addSubview:textfeld];


[[[VariableStore sharedInstance] window]addSubview:picker.view];
[[[VariableStore sharedInstance] window] makeKeyAndVisible];


[picker release];
}
4

4 回答 4

4

嘿嘿嘿。我已经让它工作了......似乎麻烦是一些动画......我现在得到了它:

在初始化:

emailController = [[UIViewController alloc] init]; [[[CCDirector sharedDirector] openGLView] addSubview:emailController.view];

点击按钮:

[[CCDirector sharedDirector] 暂停]; [[CCDirector sharedDirector] stopAnimation];

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init]; picker.mailComposeDelegate = self;

[picker setSubject:@"TEST"]; [选择器 setMessageBody:@"JAJAJA" isHTML:YES];

[emailController presentModalViewController:picker animated:YES]; [选择器发布];

MFMailComposeViewController 的委托方法

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result 错误:(NSError*)error { [[CCDirector sharedDirector] resume]; [[CCDirector sharedDirector] startAnimation];
[控制器dismissModalViewControllerAnimated:NO]; }

于 2010-08-15T00:43:02.337 回答
0

嗨,我尝试使用此代码并且有效(不适用于动画,我不知道为什么,但选择器已正确删除:)

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

{
//[选择器dismissModalViewControllerAnimated:YES]; [picker.view removeFromSuperview];

}

于 2010-05-23T09:23:20.830 回答
0

实施 inApp 电子邮件功能只需几个步骤。

Step1:添加 MessageUI 框架。

Step2:在.h文件中,#import "MessageUI/MessageUI.h"。还要添加委托 MFMailComposeViewControllerDelegate,就像和 UIViewController *emailMe;

Step3:在.m文件的init函数中添加这几行代码

CCMenuItem *emailItem = [CCMenuItemFont itemFromString: @"Email"     target:selfselector:@selector(emailCallback)];
CCMenu *menu = [CCMenu menuWithItems: emailItem, nil];
    menu.position = ccp(50,50);
    [self addChild:menu];

    emailMe = [[UIViewController alloc] init];
[[[CCDirector sharedDirector] openGLView] addSubview:emailController.view];

第 4 步:在 .m 中添加这些方法

-(void)emailCallback
{
    [[CCDirector sharedDirector] pause];
    [[CCDirector sharedDirector] stopAnimation];

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    [picker setSubject:@"Email test "];
    [picker setMessageBody:@"finally its working " isHTML:YES];

    [emailMe presentModalViewController:picker animated:YES];
    [picker release];
}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    [[CCDirector sharedDirector] resume];
    [[CCDirector sharedDirector] startAnimation];

    [controller dismissModalViewControllerAnimated:NO];
}

并运行应用程序完成:)

于 2011-01-13T06:10:18.187 回答
0

在最后一点,将选择器更改为自我,它应该可以工作。需要仔细检查的东西,您是否将您的班级设置为代表?即标题中的MFMailComposeViewControllerDelegate?如果没有,那么它将不会收到消息。

顺便说一句,这是对您发布的答案的回应,而不是最初的问题。

于 2010-01-10T00:21:41.927 回答