1

내 메일 단추를 클릭하면 MFMailComposeViewController가 구현됩니다. 아래 오류가 나타납니다.응용 프로그램이 iOS 10에서 대상에 nil 모달보기 컨트롤러를 표시하려고 시도 했습니까?

적용 대상 강한 텍스트에 전무 모달 뷰 컨트롤러를 제공하기 위해 노력

여기 내 코드입니다 : 내 코드를 잘못 무엇

NSString *iOSVersion = [[UIDevice currentDevice] systemVersion]; 
    NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; 

    NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]; 

    mailComposer = [[MFMailComposeViewController alloc]init]; 
    mailComposer.navigationBar.tintColor = [UIColor blackColor]; 
    [mailComposer.navigationBar setTitleTextAttributes: 
    @{NSForegroundColorAttributeName:[UIColor blackColor]}]; 
    mailComposer.mailComposeDelegate = self; 

    [mailComposer setSubject:@"Co - Contact Us"]; 

    [mailComposer setToRecipients:@[@"[email protected]"]]; 
    NSString *supportText = @"Enter your comment here:\n\n\n\n\n"; 
    supportText = [supportText stringByAppendingString:[NSString stringWithFormat:@"iOS Version: %@\nCorner Version:%@\nBuild:%@\n\n",iOSVersion,version, build]]; 
    [mailComposer setMessageBody:supportText isHTML:NO]; 

    [self presentViewController:mailComposer animated:YES completion:nil]; 

가. 제발 도와주십시오

답변

2

장치가 메일을 구성하지 않았거나 시뮬레이터를 사용하면 충돌 또는 예외가 발생할 수 있습니다.

mailComposer = [[MFMailComposeViewController alloc] init]; 

위의 코드 줄은 문제를 일으킬 수 있습니다. 시뮬레이터 이니셜 라이저 메서드에서 NULL 또는 nil을 반환 할 수 있습니다. ,

이 MFMailcomposerViewController에 대한
NSString *iOSVersion = [[UIDevice currentDevice] systemVersion]; 
    NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; 

    NSString * build = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]; 

    mailComposer = [[MFMailComposeViewController alloc]init]; 

    if ([MFMailComposeViewController canSendMail] && mailComposer) { 

     mailComposer.navigationBar.tintColor = [UIColor blackColor]; 
     [mailComposer.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]}]; 
     mailComposer.mailComposeDelegate = self; 

     [mailComposer setSubject:@"Corner - Contact Us"]; 

     [mailComposer setToRecipients:@[@"[email protected]"]]; 
     NSString *supportText = @"Enter your comment here:\n\n\n\n\n"; 
     supportText = [supportText stringByAppendingString:[NSString stringWithFormat:@"iOS Version: %@\nCorner Version:%@\nBuild:%@\n\n",iOSVersion,version, build]]; 
     [mailComposer setMessageBody:supportText isHTML:NO]; 

     [self presentViewController:mailComposer animated:YES completion:nil]; 
} 
+0

@visible 인터페이스는 선택기 내가 편집 한 대답을보십시오이 오류 –

+0

무엇입니까 'canSendMail'을 선언 ,

처럼 :

때문에, 단지 모달의 ViewController를 제시하기 전에 canSendMail 확인 거기에 오타 오류 @ User558 –

+0

시도했지만 IF 루프를 입력하지 않습니다 –