云文件

///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;
}

你可能感兴趣的:(云文件)