ios7 - ios: Application tried to present a nil modal view controller on target -
i developing application,the requirement open email composer on button click of uialertview.
message in message body of email copied uitextview. using following code snipt:
-(void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex{ if (buttonindex == 0) { // opening message composer } else { mfmailcomposeviewcontroller *picker = [[mfmailcomposeviewcontroller alloc] init]; picker.mailcomposedelegate = self; [picker setsubject:@"test mail"]; [picker setmessagebody:messagebody.text ishtml:yes]; [self presentviewcontroller:picker animated:yes completion:null]; } } // mail compose delegate - (void)mailcomposecontroller:(mfmailcomposeviewcontroller *)controller didfinishwithresult:(mfmailcomposeresult)result error:(nserror *)error { [self dismissviewcontrolleranimated:yes completion:null]; }
but issue getting error saying application tried present nil modal view controller on target. how can open default mail composer in ios 7?
as per apple, should check mfmailcomposeviewcontroller able send mail before sending
mfmailcomposeviewcontroller *picker = [[mfmailcomposeviewcontroller alloc] init]; if ([mfmailcomposeviewcontroller cansendmail]) { picker.mailcomposedelegate = self; [picker setsubject:@"test mail"]; [picker setmessagebody:messagebody.text ishtml:yes]; [self presentviewcontroller:picker animated:yes completion:null]; }
ref : apple dev url
Comments
Post a Comment