iOS 文件上傳文件共享功能的實現

iOSApp 文件上傳功能的實現:

這個功能其實並不難,需要用到的代碼也非常簡單,通過打開iCloud API實現,官方文檔參考: https://developer.apple.com/documentation/uikit/view_controllers/building_a_document_browser_based_app?language=objc

實現該功能還需配置項目信息:

項目配置信息截圖

支持的文件格式信息配置:

項目配置信息截圖

具體配置信息,可以參考:https://blog.csdn.net/blackyoung1111/article/details/73478035

功能實現大致代碼如下:

.h文件

#import <UIKit/UIKit.h>

@interface UIDocumentBrowserTestViewController : UIDocumentBrowserViewController

@end

.m文件

#import "UIDocumentBrowserTestViewController.h"

@interface UIDocumentBrowserTestViewController ()<UIDocumentBrowserViewControllerDelegate>

@end

@implementation UIDocumentBrowserTestViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.allowsDocumentCreation = YES;

    // 不允許多選

    self.allowsPickingMultipleItems = false;

    self.delegate = self;

    // Do any additional setup after loading the view.

}

- (void)documentBrowser:(UIDocumentBrowserViewController *)controller didPickDocumentURLs:(NSArray<NSURL *> *)documentURLs{

}

- (void)documentBrowser:(UIDocumentBrowserViewController *)controller didImportDocumentAtURL:(NSURL *)sourceURL toDestinationURL:(NSURL *)destinationURL{   

}

-(void)documentBrowser:(UIDocumentBrowserViewController *)controller didRequestDocumentCreationWithHandler:(void (^)(NSURL * _Nullable, UIDocumentBrowserImportMode))importHandler{   

}

@end

 

調用方式:

    UIDocumentBrowserTestViewController *testVC = [[UIDocumentBrowserTestViewController alloc] init];

    [self presentViewController:testVC animated:YES completion:nil];

 

就這麼多代碼就可以實現該功能了,注大家好運

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章