在iOS中打开MailComposer

时间:2015-01-05 07:12:00

标签: ios iphone email webview uinavigationcontroller

我的应用程序中有一个webView,它从本地HTML文件加载。 HTML文件包含Mail链接。 如果我点击邮件,则会打开默认邮件应用程序来发送邮件。 但我需要在我的应用程序中打开一个mailComposer。

我的代码如下

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

    NSLog(@"%@",request.URL);
    if ([[[request URL] scheme] isEqualToString:@"mailto"]) {  
        MFMailComposeViewController *composer = [[MFMailComposeViewController alloc] init];
        [composer setMailComposeDelegate:self];
        if ([MFMailComposeViewController canSendMail]) {
            NSString *strEmail = [NSString stringWithFormat:@"%@",request.URL];
            NSString *subString = [[strEmail componentsSeparatedByString:@":"] lastObject];
            [composer setToRecipients:[NSArray arrayWithObjects:subString, nil]];
            [composer setSubject:@"Kreativ-Q"];
            [composer setMessageBody:@"" isHTML:YES];
            [composer setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
            [self presentViewController:composer animated:YES completion:nil];
        }    }
    return YES;
}

帮我解决这个问题

感谢

0 个答案:

没有答案