0

我正在打开 web url,UIWebView其中包含一些带有 java 脚本操作的按钮。点击此按钮后,此页面电子邮件中有一个按钮我得到电子邮件地址和电子邮件正文

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{if( [requestString rangeOfString:@"email.com"].location!=NSNotFound){if ([MFMailComposeViewController canSendMail]){if (!mailer)
                 mailer = [[MFMailComposeViewController alloc] init];

               mailer.mailComposeDelegate = self;
                NSString *subject = [dataManager.dictTransalations objectForKey:@"71"];
                [mailer setSubject:subject];

                NSArray *toRecipients = [NSArray arrayWithObjects:distributorEmailAddress.length > 0 ? distributorEmailAddress:@"", nil];

                [mailer setToRecipients:toRecipients];
                [mailer setMessageBody:@"" isHTML:NO];
                isFromMailVC=YES;

                //[self presentViewController:mailer animated:YES completion:NULL];
                [self presentModalViewController:mailer animated:YES];
                }}return NO;} 

- (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.");
    break;
    case MFMailComposeResultFailed:
    NSLog(@"Mail failed: the email message was not saved or queued, possibly due to an error.");
    break;
    default:
    NSLog(@"Mail not sent.");
    break;
}
[controller dismissModalViewControllerAnimated:YES];
NSLog(@" Mail Composer Error = %@",error);
}

关闭mailComposeController UIWebViewjava 脚本后,其他按钮不起作用,并且在另一个选项卡中点击另一个包含一些产品列表的 web url 也显示空白和头部图像。

当我在文档目录中看到缓存中的数据时,它在 List 表的 100000.db 中。

我不明白为什么在打开和关闭 mailcompose 后它没有加载。从后台退出应用程序后,它可以工作。

有什么方法可以UIWebView在 iOS 5.1 中调试页面?

4

1 回答 1

0

我昨天在 iOS7 中遇到了同样的事情,几分钟前找到了解决方案。也许它会帮助你。

检查你的viewWillDisappear方法。我的看起来像这样:

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    self.webView.delegate = nil;
    self.webView = nil;
    // whatever else you do
}

错误出现在分配中:MFMailComposeViewController出现viewDidDisappear并被调用时,webView丢失了它的委托,因此没有捕获点击。

如果您正在为 iOS6 或更高版本编程,则应该这样:

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    // whatever else you do
}

但是,如果您正在为 iOS5 或更早版本编程并且由于某种原因必须分配,那么添加以下内容:nil

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.webView.delegate = nil;
    self.webView = nil;
    // whatever else you do
}

注意:iOS6 和更新版本不推荐使用此方法,因为自 iOS6 以来从未调用过此方法。

于 2014-09-17T09:15:31.427 回答