iOS文件展示及分享(一) UIDocumentInteractionController

公司項(xiàng)目里有云盤(pán)功能,所以需要做文件展示和下載功能。
快速開(kāi)發(fā)所以使用了系統(tǒng)自帶的UIDocumentInteractionController
UIDocumentInteractionController 是系統(tǒng)提供的用來(lái)展示文件的,但是展示的文件必須是下載到本地的文件,而不能在線瀏覽,所以需要將文件存到本地。

NSURL *url = [NSURL fileURLWithPath:filePath];//filePath是文件保存的位置

UIDocumentInteractionController  * documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url];

[documentInteractionController setDelegate:self];

[documentInteractionController presentPreviewAnimated:YES];//展示文件詳情

//如果想直接分享到第三方APP中
//[documentInteractionController presentOpenInMenuFromRect:self.view.bounds inView:self.view animated:YES];

實(shí)現(xiàn)代理

#pragma mark - UIDocumentInteractionController 代理方法
//從哪個(gè)控制器打開(kāi)
- (UIViewController *)documentInteractionControllerViewControllerForPreview:(UIDocumentInteractionController *)controller{
    return self;
}

- (UIView *)documentInteractionControllerViewForPreview:(UIDocumentInteractionController *)controller{
    return self.view;
}

- (CGRect)documentInteractionControllerRectForPreview:(UIDocumentInteractionController *)controller{
    return self.view.bounds;
}
最后編輯于
?著作權(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)容

  • 框架簡(jiǎn)介--主要定位于互聯(lián)網(wǎng)企業(yè)架構(gòu),已內(nèi)置企業(yè)信息化系統(tǒng)的基礎(chǔ)功能和高效的代碼生成工具,包括:系統(tǒng)權(quán)限組件、數(shù)據(jù)...
    swiftie10閱讀 663評(píng)論 1 1
  • 一、當(dāng)你到了18歲,你可能面臨著兩個(gè)重大的決定。 1.你將如何謀生 2.你選擇一個(gè)什么樣的人生伴侶 首先,如果有可...
    千言萬(wàn)語(yǔ)娟娟閱讀 671評(píng)論 0 0
  • 今天分享一張很有名的木椅。學(xué)名:伊姆斯彎木躺椅 。作為美國(guó)最重要的現(xiàn)代藝術(shù)博物館MOMA的永久收藏品,伊姆斯彎木躺...
    素心小筑閱讀 361評(píng)論 0 1

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