Как отправить письмо по iPad - NSobject класс
У меня есть проект очень просто как проекты 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
1 ответ
Я думаю, вы не импортируете рамки
#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];
}