要打开一个网页,我们之前常见的方法有两种
- Safari openULR:自带很多功能(进度条,刷新,前进,后退),但是必须要跳出当前应用。
2.UIWebView:在当前应用打开,不能实现进度条
现在iOS 9中 增加了一个新的API:SFSafariViewController
我们看一下具体用法:
1.导入
#import <SafariServices/SafariServices.h>
2.使用
NSURL *url = [NSURL URLWithString:item.url];
SFSafariViewController *safariVc = [[SFSafariViewController alloc] initWithURL:url];
// self.navigationController.navigationBarHidden = YES;
// [self.navigationController pushViewController:safariVc animated:YES];
// 官方推荐我们用modal的形式
[self presentViewController:safariVc animated:YES completion:nil];
上面modal出一个SFSafariViewController
3、SFSafariViewController的delegate
方法
#pragma mark - SFSafariViewControllerDelegate
/**
点击了SFSafariViewController控制器试图 顶部左边的 Done 按钮
*/
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller
{
//[self.navigationController popViewControllerAnimated:YES];
}