iOS 共享到oneDrive

iOS 共享爬坑记

微软的oneDrive,说实话也绕了好久才终于找到位置,毕竟微软的东西实在是太多了,想要找到oneDrive并注册App还是费了一番劲儿。

info配置[图片上传中...(截屏2019-11-29下午3.30.53.png-242571-1575012656363-0)] .png

URL types.png

pod导入

pod 'OneDriveSDK' #OC for OneDrive
#pod 'MSAL' #swift for OneDrive

注册

#import 

[ODClient setMicrosoftAccountAppId:@"b0cd081d-67ee-4d37-a91b-ac1153e6c368" scopes:@[@"onedrive.readwrite",@"offline_access"]];
[ODClient setActiveDirectoryAppId:@"b0cd081d-67ee-4d37-a91b-ac1153e6c368" redirectURL:@"msalb0cd081d-67ee-4d37-a91b-ac1153e6c368://auth"];

开始没有设置回调地址,一直提示我有问题,我用新版的oneDrive后台注册App,将回调地址写上去,一样告诉我回调地址有问题,最后没有办法,直接使用他们默认给出的回调地址,直接就成功了……嗯……玩不动。

开始

- (void)oneDriveAction {
    [self oneDriveAuthor];
}

授权

// 授权
- (void)oneDriveAuthor {
    [ODClient clientWithCompletion:^(ODClient *client, NSError *error){
       if (!error){
           NSLog(@"oneDrive授权成功");
           // 检索用户驱动
//           [[[client drive] request] getWithCompletion:^(ODDrive *drive, NSError *error){
//               //Returns an ODDrive object or an error if there was one
//               NSLog(@"");
//           }];
           // 获取用户根文件夹驱动
//           [[[[client drive] items:@"root"] request] getWithCompletion:^(ODItem *item, NSError *error){
//               //Returns an ODItem object or an error if there was one
//               NSLog(@"");
//           }];
           
           // 上传文件
           [self oneDriveUploadFile:[[NSBundle mainBundle] pathForResource:@"4" ofType:@"pdf"] client:client];
       }else {
           NSLog(@"oneDrive授权失败");
       }
    }];
}

上传文件

// 上传
- (void)oneDriveUploadFile:(NSString *)filePath client:(ODClient *)client{
    NSLog(@"file begin upload by oneDrive");
    [[[[[[client drive] items:@"root"] itemByPath:filePath.lastPathComponent] contentRequest] uploadFromFile:[NSURL fileURLWithPath:filePath] completion:^(ODItem *response, NSError *error) {
        if (error) {
            NSLog(@"上传失败");
        }else {
            NSLog(@"");
        }
    }] execute];
}

帮助文档:
oneDrive帮助文档

你可能感兴趣的:(iOS 共享到oneDrive)