0

我的项目非常简单,就像 Unity 项目一样,我想添加一个新功能 - 发送电子邮件应用程序屏幕截图,

我尝试了很多方法来做到这一点,但我是 IOS 的新手,需要你的帮助:(

此版本工作正常,但单击按钮后我没有看到电子邮件表单

代码非常简短 - 我希望有人能帮助我:(((

SampleViewsAppDelegate.h

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <MapKit/MKMapView.h>
#import <MessageUI/MessageUI.h>

#import "tiDFusionMobile.h"

@interface SampleViewsAppDelegate : NSObject     <UIApplicationDelegate,MFMailComposeViewControllerDelegate> {

    ///Application Window
    UIWindow *mWindow;

    UIViewController *rootViewController;

    ///Application views
    UIView    *mRender;

    tiComponent* mPlayer;
}

///IBOutlet properties
@property (nonatomic, retain) IBOutlet UIWindow *mWindow;
@property (nonatomic, retain) IBOutlet UIViewController *rootViewController;
@property (nonatomic, retain) IBOutlet UIView *mRender;


- (IBAction)openMailBtn:(id)sender;
- (void)start;
- (void)stop;

@end

文件毫米

#import "SampleViewsAppDelegate.h"
@implementation SampleViewsAppDelegate
@synthesize mWindow;
@synthesize mRender;
@synthesize rootViewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
    // allocate the Component
    mPlayer = [tiComponent alloc];

    // set correct renderer
    [mPlayer setRendererType:[tiComponent TI_RENDERER_GLES2]];

    // initialze
    [mPlayer initialize:mRender];

    // start scenario
    [self start];
    return YES;
}

- (void)dealloc
{
    [self stop];

    //If the player is still instanciated, it is terminated and released
    if (mPlayer)
    {
        [mPlayer terminate];    
        [mPlayer release];
        mPlayer = nil;
    }

    [mRender release];

    [mWindow release];

    [super dealloc];
}

- (IBAction)openMailBtn:(id)sender {

    rootViewController = (UIViewController*)
    [(SampleViewsAppDelegate*)[[UIApplication sharedApplication] delegate] rootViewController];

    if ([MFMailComposeViewController canSendMail]) {
    // compose
    MFMailComposeViewController* mail = [[MFMailComposeViewController alloc] init];
    mail.mailComposeDelegate = self;

    //format message
    NSArray *recipientsArray = [[NSArray alloc] initWithObjects:@"test@aaaa.com", nil];
    [mail setToRecipients:recipientsArray];
    NSString *emailBody = @"DSDSDSDS";
    [mail setSubject:[NSString stringWithFormat:@"AAAAAA"]];

    //UIImage *myImage = [UIImage imageNamed:@"mobiletuts-logo.png"];
    //NSData *imageData = UIImagePNGRepresentation(myImage);
    //[mail addAttachmentData:imageData mimeType:@"image/png" fileName:@"mobiletutsImage"];

    [mail setMessageBody:emailBody isHTML:YES];

    //send
    //if (controller)
        [rootViewController presentModalViewController:mail animated:YES];
    [mail release];

    } else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failure"
                                                        message:@"Your device doesn't support the composer sheet"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles: nil];
        [alert show];
        [alert release];
    }
 }

#pragma mark - MFMailComposeController delegate

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
    switch (result)
    {
        case MFMailComposeResultCancelled:
            NSLog(@"Mail cancelled: you cancelled the operation and no email message was queued");
            break;
        case MFMailComposeResultSaved:
            NSLog(@"Mail saved: you saved the email message in the Drafts folder");
            break;
        case MFMailComposeResultSent:
            NSLog(@"Mail send: the email message is queued in the outbox. It is ready to send the next time the user connects to email");
            break;
        case MFMailComposeResultFailed:
            NSLog(@"Mail failed: the email message was nog saved or queued, possibly due to an error");
            break;
        default:
            NSLog(@"Mail not sent");
            break;
    }

    [self dismissViewControllerAnimated:YES complete:nil];
}

- (void)start
{
    if (mPlayer != nil) {
        BOOL isLoaded = [mPlayer loadScenario:@"Scenario/SampleViews_GLES1/project.dpd"];
            if (isLoaded) {
            [mPlayer playScenario];
        }       
    }
}

- (void)stop
{
    if (mPlayer && ![mPlayer isScenarioPaused]) {
        [mPlayer pauseScenario];
    }

}

@end
4

1 回答 1

0

我猜你没有导入框架

#import <MessageUI/MessageUI.h> 
#import <MessageUI/MFMailComposeViewController.h> 
@interface MailClassViewController : UIViewController<MFMailComposeViewControllerDelegate>

然后是显示电子邮件屏幕的代码:

- (IBAction)openMailBtn:(id)sender {

if([MFMailComposeViewController canSendMail]) {
    MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
    mailCont.mailComposeDelegate = self;
    [mailCont setSubject:@"Your email"];
    [mailCont setMessageBody:[@"Your body for this message is " stringByAppendingString:@" this is awesome"] isHTML:NO];
    NSString *file = [documentsDirectory stringByAppendingPathComponent:@"MaintenanceRequest.pdf"];

   //IF YOU DONT WANT TO ATTACH FILE THEN COMMENT IT
    NSData *data=[NSData dataWithContentsOfFile:file];
    [mailViewController addAttachmentData:data mimeType:@"application/pdf" fileName:@"MaintenanceRequest.pdf"];

    [self presentViewController:mailCont animated:YES completion:nil];
 }

}

- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
//handle any error
[controller dismissViewControllerAnimated:YES completion:nil];
}
于 2013-08-17T13:22:26.150 回答