云文件

2019-11-05  本文已影响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;
}

上一篇下一篇

猜你喜欢

热点阅读