工欲善其事必先利其器
话不多说,直接上图了。
-
先去Apple官网配置证书 这里你可以多创建几个开发的正式的,IDENTIFIER不一样就可以了。 -
找到你项目的IDENTIFIER 点进去选择你给这个证书创建的iCloud就可以了。 -
配置Xcode,每个项目的正式和测试都有对应的ICloud,选择对应的就可以了
UIDocumentPickerViewController浏览文件
@property (nonatomic, strong) UIDocumentPickerViewController *documentPicker;
@property (nonatomic, copy) NSArray *types;
-(NSArray *)types {
return @[
@"public.data",
];
}
- (UIDocumentPickerViewController *)documentPicker {
if (_documentPicker == nil) {
_documentPicker = [[UIDocumentPickerViewController alloc] initWithDocumentTypes:self.types inMode:UIDocumentPickerModeOpen];
_documentPicker.delegate = self;
_documentPicker.modalPresentationStyle = UIModalPresentationFullScreen;
}
return _documentPicker;
}
[self presentViewController:self.documentPicker animated:YES completion:nil];
#pragma mark ???- UIDocumentPickerDelegate
- (void)documentPicker:(UIDocumentPickerViewController *)controller didPickDocumentsAtURLs:(NSArray<NSURL *> *)urls {
NSFileCoordinator *fileCoordinator = [[NSFileCoordinator alloc] init];
NSError *error;
[fileCoordinator coordinateReadingItemAtURL:urls.firstObject options:0 error:&error byAccessor:^(NSURL *newURL) {
NSString *fileName = [newURL lastPathComponent];
NSError *error = nil;
NSData *fileData = [NSData dataWithContentsOfURL:newURL options:NSDataReadingMappedIfSafe error:&error];
if (fileData != nil) {
}
NSString *filePath = [NSTemporaryDirectory() stringByAppendingPathComponent:fileName];
NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isExists = [fileManager fileExistsAtPath:filePath];
if (isExists) {
[fileManager removeItemAtPath:filePath error:nil];
}
BOOL isCreate = [fileManager createFileAtPath:filePath contents:nil attributes:nil];
if (isCreate) {
BOOL isWrite = [fileData writeToFile:filePath options:NSDataWritingAtomic error:nil];
if (isWrite) {
}
}
}];
[urls.firstObject stopAccessingSecurityScopedResource];
}
计算文件大小 返回字节数
- (unsigned long long)fileSizeOfPath:(NSString *)path
{
unsigned long long size = 0;
NSFileManager *manager = [NSFileManager defaultManager];
BOOL isDir = NO;
BOOL exist = [manager fileExistsAtPath:path isDirectory:&isDir];
if (!exist) return size;
if (isDir) {
NSDirectoryEnumerator *enumerator = [manager enumeratorAtPath:path];
for (NSString *subPath in enumerator) {
NSString *fullPath = [path stringByAppendingPathComponent:subPath];
size += [manager attributesOfItemAtPath:fullPath error:nil].fileSize;
}
}else{
size += [manager attributesOfItemAtPath:path error:nil].fileSize;
}
return size;
}
|