我正在UIWebView
中打开Web url,其中包含一些带有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
UIWebView
java脚本不适用于其他按钮,并且在另一个选项卡中点击另一个包含某些产品列表的Web url也显示带有头部图像的空白。
当我在文档目录中的缓存中看到数据时,它在 100000.db 对于列表表。
我不知道为什么它在打开和关闭邮件撰写后不加载。 从后台退出应用程序后,它可以工作。
有什么方法可以在iOS 5.1中调试UIWebView
页面?
我昨天在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 以来从未调用过此方法。