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];

 

就这么多代码就可以实现该功能了,注大家好运

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

iOS首席贴膜师

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值