iOS 9之后新VC —— SFSafariViewController

項(xiàng)目中可能會(huì)有這樣的需求:

1.單純的展示一個(gè)網(wǎng)頁(yè)來(lái)介紹說(shuō)明內(nèi)容; 一般我們都會(huì)使用UIWebViewController 進(jìn)行加載,有點(diǎn)麻煩性能也不好。
2.不用跳轉(zhuǎn)到Safari,就有了Safari瀏覽器完全功能
許多使用者想要在他們的 App 中使用完整的 Safari 瀏覽器功能,但是又不希望強(qiáng)制使用者跳離 App 去使用 Safari 瀏覽器(這會(huì)影響使用者留存率),而且能夠?qū)⒕W(wǎng)頁(yè)內(nèi)容整合到 Safari 瀏覽器之中。

這時(shí)候 SFSafariViewController 就是你的最佳選擇。 但是只能在iOS 9系統(tǒng)之后才可以使用。

步驟:

1.首先導(dǎo)入:
#import <SafariServices/SafariServices.h>
2.初始化瀏覽器

//加載一個(gè)url,是否啟用閱讀器功能 **只能加載標(biāo)準(zhǔn)的http https URL**, 不然會(huì)崩潰
    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:說(shuō)明:是否使用閱讀器功能。如想要顯示的是 Wikipedia 的內(nèi)容,要使用的是閱讀器( Reader )的功能。閱讀器是 Safari 中一個(gè)很方便的功能,可以從網(wǎng)站截取并顯示重要的內(nèi)容。

對(duì)應(yīng)的代理方法解釋
@optional
說(shuō)明:主要使用這兩個(gè)代理方法,
/*! @abstract Delegate callback called when the user taps the Done button. Upon this call, the view controller is dismissed modally. 
說(shuō)明:不用實(shí)現(xiàn)這個(gè)代理方法,點(diǎn)擊Done 也可以dismiss SFSafariViewController 親測(cè)可以的
*/
- (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.
說(shuō)明: 加載完成可以做一些你想做的事情。
 */
- (void)safariViewController:(SFSafariViewController *)controller didCompleteInitialLoad:(BOOL)didLoadSuccessfully;

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容