iOS 9之后新VC —— SFSafariViewController

项目中可能会有这样的需求:

1.单纯的展示一个网页来介绍说明内容; 一般我们都会使用UIWebViewController 进行加载,有点麻烦性能也不好。 2.不用跳转到Safari,就有了Safari浏览器完全功能 許多使用者想要在他們的 App 中使用完整的 Safari 浏览器功能,但是又不希望强制使用者跳离 App 去使用 Safari 瀏覽器(这会影响使用者留存率),而且能夠將网页內容整合到 Safari 浏览器之中。

这时候 SFSafariViewController 就是你的最佳选择。 但是只能在iOS 9系统之后才可以使用。

####步骤: 1.首先导入: #import <SafariServices/SafariServices.h> 2.初始化浏览器

//加载一个url,是否启用阅读器功能
    SFSafariViewController *safariVC = [[SFSafariViewController alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com"] entersReaderIfAvailable:YES];
    safariVC.delegate = self;
    [self presentViewController:safariVC animated:YES completion:nil];
复制代码

3.引入代理 SFSafariViewControllerDelegate

entersReaderIfAvailable:说明:是否使用阅读器功能。如想要顯示的是 Wikipedia 的內容,要使用的是阅读器( Reader )的功能。阅读器是 Safari 中一個很方便的功能,可以从网站截取并显示重要的內容。

#####对应的代理方法解释

@optional
说明:主要使用这两个代理方法,
/*! @abstract Delegate callback called when the user taps the Done button. Upon this call, the view controller is dismissed modally. 
说明:貌似不用实现这个代理方法,点击Done 也可以dismiss SFSafariViewController 亲测可以的
*/
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller;

/*! @abstract Invoked when the initial URL load is complete.
    @param didLoadSuccessfully YES if loading completed successfully, NO if loading failed.
    @discussion This method is invoked when SFSafariViewController completes the loading of the URL that you pass to its initializer. It is not invoked for any subsequent page loads in the same SFSafariViewController instance.
说明: 加载完成可以做一些你想做的事情。
 */
- (void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully;

复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值