云文件

作者: 赤焰军少帅林殊 | 来源:发表于2019-11-05 20:06 被阅读0次
    ///iCloud文件上传使用
    @interface WeDocument : UIDocument
    
    @property (nonatomic, strong, nullable) NSData *data;
    //文件名
    @property (nonatomic, copy, nullable) NSString *fileName;
    //文件类型
    @property (nonatomic, copy, nullable) NSString *MIMEType;
    //文件大小
    @property (nonatomic, assign) NSUInteger length;
    
    @end
    
    @implementation WeDocument
    
    - (BOOL)loadFromContents:(id)contents ofType:(NSString *)typeName error:(NSError * _Nullable __autoreleasing *)outError
    {
        //目前不支持.page
        if ([contents isKindOfClass:[NSData class]])
        {
            self.data = [contents copy];
            self.fileName = self.fileURL.lastPathComponent;
            if (self.fileName && self.fileName.length) {
                NSRange startRange = [self.fileName rangeOfString:@"."];
                self.MIMEType = [self.fileName substringFromIndex:startRange.location];
            }
            self.length = self.data.length;
        }
        else {
            NSLog(@"读取文件出错!");
            return NO;
        }
        return YES;
    }
    
    

    相关文章

      网友评论

          本文标题:云文件

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