情况是这样的:
我正在创建一个模型,它将实现MFMessageComposeVIEwController而不是直接在VIEwController中执行它.现在,当我实现presentModalVIEwController ::方法时,它工作正常(出现mail.app接口)但是当我单击mail.app界面中的取消/发送按钮时,它不会忽略mail.app ..
它像这样的东西:
MSGVIEwController的一个方法片段,它实现了发送邮件模型:
- (IBAction)openEmail:(ID)sender { Messaging *mail = [[Messaging alloc]initWithModal:self]; [mail emailinvitation:@"Eventz Date" eventAt:@"Eventz Location" withImage:nil]; [self.sendingStatus setText:mail.sendingStatus];}
我实现消息传递的模型:
Messaging.h
#import <Foundation/Foundation.h>#import <MessageUI/MessageUI.h>@interface Messaging : NSObject <MFMailComposeVIEwControllerDelegate,MFMessageComposeVIEwControllerDelegate>@property (nonatomic,copy) Nsstring *sendingStatus;@property (nonatomic,retain) ID modal;- (ID)initWithModal:(ID)modal;- (voID)emailinvitation:(Nsstring *)eventDate eventAt:(Nsstring *)eventLocation withImage:(UIImage *)imageAttachment;@end
Messaging.m
#import "Messaging.h"@implementation Messaging@synthesize sendingStatus = _sendingStatus;@synthesize modal = _modal;- (ID)initWithModal:(ID)modal{ self = [super init]; self.modal = modal; return self;}- (voID)emailinvitation:(Nsstring *)eventDate eventAt:(Nsstring *)eventLocation withImage:(UIImage *)imageAttachment{ MFMailComposeVIEwController *mailer = [[MFMailComposeVIEwController alloc] init]; if ([MFMailComposeVIEwController canSendMail]){ mailer.mailComposeDelegate = self; [mailer setSubject:@"Event Invitation"]; [mailer setMessageBody:@"message body"] isHTML:NO]; if(imageAttachment != nil){ NSData *imageData = UIImagePNGRepresentation(imageAttachment); [mailer addAttachmentData:imageData mimeType:@"image/png" filename:@"imagefilename"]; } [self.modal presentModalVIEwController:mailer animated:YES]; return; } [self deviceDoNotSupportMessaging]; }- (voID)mailComposeController:(MFMailComposeVIEwController*)controller dIDFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{ NSLog(@"called"); switch (result) { case MFMailComposeResultCancelled: self.sendingStatus = @"Mail sending cancelled."; break; case MFMailComposeResultSaved: self.sendingStatus = @"Mail saved."; break; case MFMailComposeResultSent: self.sendingStatus = @"Mail sent."; break; case MFMailComposeResultFailed: self.sendingStatus = @"Mail sending Failed."; break; default: self.sendingStatus = @"Mail not sent."; break; } [controller dismissModalVIEwControllerAnimated:YES];}
BTW,NSLog(@“叫”);在.m中实际上并未调用…
有人可以有任何建议吗?感谢:D
Messaging *mail = [[Messaging alloc]initWithModal:self];
所以我改变了一件事,我在我的通话类中发送了一个Strong Property:
@property (strong,nonatomic) Messaging *mail;
然后这样称呼它:
mail = [[Messaging alloc]initWithModal:self]; [mail emailinvitation:@"Eventz Date" eventAt:@"Eventz Location" withImage:nil]; NSLog(@"Called the emailinvitation");
调用了日志语句,我甚至确保MailComposer得到了正确的响应:
- (voID)mailComposeController:(MFMailComposeVIEwController*)controller dIDFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{ NSLog(@"called"); switch (result) { case MFMailComposeResultCancelled: self.sendingStatus = @"Mail sending cancelled."; NSLog(@"Mail Cancelled"); break; case MFMailComposeResultSaved: self.sendingStatus = @"Mail saved."; NSLog(@"Mail Saved"); break; case MFMailComposeResultSent: self.sendingStatus = @"Mail sent."; NSLog(@"Mail Sent"); break; case MFMailComposeResultFailed: self.sendingStatus = @"Mail sending Failed."; NSLog(@"Mail Failed"); break; default: self.sendingStatus = @"Mail not sent."; NSLog(@"Mail Not Sent"); break; } [controller dismissModalVIEwControllerAnimated:YES];}
它确实如此.
顺便说一句 – 我喜欢你这样做的方式.这是OOP应该完成的方式.
总结以上是内存溢出为你收集整理的iphone – iOS:MFMailComposeViewController无法处理模型全部内容,希望文章能够帮你解决iphone – iOS:MFMailComposeViewController无法处理模型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)