我已经使用CTAssetsPickerController库访问iOS照片。我已将照片从MAC通过iTunes同步到iPhone,并且照片在“我的Mac”中在我的手机库中提供。但是,当我从选择器中选择资产时,在资产信息中,我得到的文件URL为file:///var/mobile/Media/PhotoData/Sync/100SYNCD/IMG_0002.JPG,并且从给定的URL中找不到数据]
**PHAsset *asset = [self assetAtIndexPath:indexPath];
if (asset.mediaType == 1) {
if (@available(iOS 9.0, *)) {
NSArray *arr = [PHAssetResource assetResourcesForAsset:asset];
if (arr) {
PHAssetResource *resource = arr.firstObject;
if (resource) {
NSUInteger fileSize = [[resource valueForKey:@"fileSize"] integerValue];
NSLog(@"size %lu",(unsigned long)fileSize);
if (fileSize < self.picker.maxLimitSize) {
[self.picker selectAsset:asset];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
NSURL *fileURL = [info valueForKey:@"PHImageFileURLKey"];
NSData *imagedata = [NSData dataWithContentsOfURL:fileURL];
[self.picker addURL:fileURL atIndex:self.selectedAssetsCounts];
++self.picker.selectMediaFiles;
}];
});
}else{
[self showAlertMessageWithTitle: CTAssetsPickerLocalizedString(@"sizelimitexceed", nil) andMessage:CTAssetsPickerLocalizedString(@"mediasizelimitmessage", nil) withIndex:indexPath];
}
}
}**
Please guide me . thanks in advance.
我已经使用CTAssetsPickerController库访问iOS照片。我已将照片从MAC通过iTunes同步到iPhone,并且照片在“我的Mac”中在我的手机库中提供。但是...
您不应该依赖PHImageFileURLKey
。它从未得到官方支持,甚至没有文档记录。使用PHImageManager的方法之一作为