【发布时间】:2012-01-17 12:24:39
【问题描述】:
伙计们。我正在尝试在 Safari 中从我的 webView 中实现打开链接。有时它可以完美运行,有时会显示非常糟糕的访问权限。 这是我的代码:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
urlWillShow = [request mainDocumentURL];
return YES;
}
- (IBAction)openInSafari {
NSLog(@"Will try to open in safari link: %@", [urlWillShow absoluteString]);
if ([[urlWillShow scheme] isEqualToString:@"http"] || [[urlWillShow scheme] isEqualToString:@"https"]) {
BOOL canLoad = [[UIApplication sharedApplication] canOpenURL:urlWillShow];
if (canLoad == YES) {
[[UIApplication sharedApplication] openURL:urlWillShow];
}
}
}
【问题讨论】:
-
没有足够的信息进行调试。哪条线路有问题?
-
检查您在获得 BAD_ACCESS 的“有时”期间是否在 urlWillShow 中确实有一个 URL。
-
您是使用 ARC,还是手动保留/释放?
-
我有 urlWillShow,因为 uiwebview 将永远加载到这个视图控制器中。我只有两行,编辑 urlWillShow: *.h NSURL *urlWillShow;和行,显示在我的问题中
标签: iphone objective-c ios xcode uiwebview