美文网首页
ios 访问icould和系统本身的文件

ios 访问icould和系统本身的文件

作者: 墨凌风起 | 来源:发表于2018-05-19 19:36 被阅读7次

pragma mark -- 发送文件

-(void)onSendFileBtnPressed:(id)sender{
    if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) {
        //older than iOS 8 code here
        NSLog(@"IOS8以上才支持icloud drive.");
    } else {
        //iOS 8 specific code here
        NSArray *documentTypes = @[@"public.content", @"public.text", @"public.source-code ", @"public.image", @"public.audiovisual-content", @"com.adobe.pdf", @"com.apple.keynote.key", @"com.microsoft.word.doc", @"com.microsoft.excel.xls", @"com.microsoft.powerpoint.ppt"];
        
        UIDocumentPickerViewController *documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];
        documentPicker.delegate = self;//代理 UIDocumentPickerDelegate
        documentPicker.modalPresentationStyle = UIModalPresentationFormSheet;
        [self presentViewController:documentPicker animated:YES completion:nil];
    }
}
#pragma mark-- UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentAtURL:(NSURL *)url {
    BOOL fileUrlAuthozied = [url startAccessingSecurityScopedResource];
    if(fileUrlAuthozied){
        NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
        NSError *error;
        
        [fileCoordinator coordinateReadingItemAtURL:url options:0 error:&error byAccessor:^(NSURL *newURL) {
            //文件路径
            NSString *urlStr =url.absoluteString;

           //你的从操作
        }];
    }else{
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"" message:NSLocalizedString(@"申请访问受限", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"I know", nil) otherButtonTitles: nil];
        [alert show];
        [alert release];;
        
    }
}

相关文章

  • ios 访问icould和系统本身的文件

    pragma mark -- 发送文件

  • iOS 文件选择

    文件来源是从手机资源库获取(不包括沙盒文件),即iCould云盘。在iOS11之后系统自带的app文件中的内容就是...

  • iCloud云存储开发实例(亲测可用)

    1. iCould Key-Value storage 2. iCould Documents: iOS: iCl...

  • 清理缓存

    每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用的文件系统隔离,ios系统不允许访问其他应用...

  • iOS数据存储

    每个ios应用都有自己的应用沙盒,应用沙盒就是文件系统目录,与其他应用的文件系统隔离,ios系统不允许访问其他应用...

  • iOS NSFileManager初探

    iOS NSFileManager初探 使用NSFileManager 文件系统接口 允许访问文件夹内容 创建,重...

  • iOS 的沙盒路径&文件操作

    每个iOS 应用都有自己的沙盒路径,应用沙盒就是文件系统目录,与其他应用的文件系统隔离,iOS应用不允许访问其他应...

  • iOS逆向之越狱(iPhone4s 9.3.5)

    因为逆向的前提是需要访问iOS全系统的文件,而访问全系统文件的前提是越狱,因此逆向的第一步就是对手机越狱,不同的系...

  • Java输入输出

    File类 1. File类 File能新建、删除、重命名文件和目录,但不能访问文件内容本身 1.1 访问文件和目...

  • iOS安全审计入门

    iOS沙盒 iOS沙盒机制简述起来就是,iOS应用程序只能在为该程序创建的文件系统中读取文件,不可以去其他地方访问...

网友评论

      本文标题:ios 访问icould和系统本身的文件

      本文链接:https://www.haomeiwen.com/subject/ctyadftx.html