iOS过滤类型 UIDocumentPickerViewCont

2023-06-04  本文已影响0人  你飞跃俊杰
///定于类型
typedef enum {
    BNIMFileTypeimage=1<<0,
    BNIMFileTypevideo=1<<1,
    BNIMFileTypeaudio=1<<2,
    BNIMFileTypexls=1<<3,
    BNIMFileTypexlsx=1<<4,
    BNIMFileTypedoc=1<<5,
    BNIMFileTypedocx=1<<6,
    BNIMFileTypepdf=1<<7,
    BNIMFileTypetxt=1<<8,
} BNIMFileType;

///将传入的字符串转换成对应的类型
+(BNIMFileType)getFileType:(NSArray *)array{
    BNIMFileType type = 0;
    if([array containsObject:@"video"]){
        type = type|BNIMFileTypevideo;
    }
    if([array containsObject:@"audio"]){
        type = type|BNIMFileTypeaudio;
    }
    if([array containsObject:@"xls"]){
        type = type|BNIMFileTypexls;
    }
    if([array containsObject:@"xlsx"]){
        type = type|BNIMFileTypexlsx;
    }
    if([array containsObject:@"doc"]){
        type = type|BNIMFileTypedoc;
    }
    if([array containsObject:@"docx"]){
        type = type|BNIMFileTypedocx;
    }
    if([array containsObject:@"pdf"]){
        type = type|BNIMFileTypepdf;
    }
    if([array containsObject:@"txt"]){
        type = type|BNIMFileTypetxt;
    }
    if([array containsObject:@"image"]){
        type = type|BNIMFileTypeimage;
    }
    return type;
}
////转换成苹果自带的类型
+(NSArray *)getDocumentTypes:(BNIMFileType)type{
    NSMutableArray *array = NSMutableArray.array;
    if(type&BNIMFileTypevideo){
        [array addObject:@"public.movie"];
    }
    if(type&BNIMFileTypeaudio){
        [array addObject:@"public.audio"];
    }
    if(type&BNIMFileTypexls){
        [array addObject:@"com.microsoft.excel.xls"];
    }
    if(type&BNIMFileTypexlsx){
        [array addObject:@"com.microsoft.excel.xlsx"];
    }
    if(type&BNIMFileTypedoc){
        [array addObject:@"com.microsoft.word.doc"];
    }
    if(type&BNIMFileTypedocx){
        [array addObject:@"com.microsoft.word.docx"];
    }
    if(type&BNIMFileTypepdf){
        [array addObject:@"com.adobe.pdf"];
    }
    if(type&BNIMFileTypetxt){
        [array addObject:@"public.text"];
    }
    if(type&BNIMFileTypeimage){
        [array addObject:@"public.image"];
    }
    return array;
}
///转换成其他类型,比如聊天记录

使用

- (void)selectiCloudFile{
//    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"];
    NSArray *documentTypes = nil;
    if([self.docTypeArray isKindOfClass:NSArray.class]&&self.docTypeArray.count){
        documentTypes = [BNIMFileUploadOrSendManager getDocumentTypes:[BNIMFileUploadOrSendManager getFileType:self.docTypeArray]];
    }
    UIDocumentPickerViewController *documentPickerViewController = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:documentTypes inMode:UIDocumentPickerModeOpen];
    documentPickerViewController.delegate = self;
    [_mainVC presentViewController:documentPickerViewController animated:YES completion:nil];
}
上一篇下一篇

猜你喜欢

热点阅读