我想获取在 photoLibrary 中拍摄的最后一张照片并将其添加到将在 UIActivivtyViewController 中使用的数组中。当 UIActivityViewController 出现时,图像不会显示,并且 UIImage 似乎从未添加到数组中。
这是我所拥有的,
NSMutableArray *items = [[NSMutableArray alloc]init];
[items addObject:@"someText"];
PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
PHAsset *lastAsset = [fetchResult lastObject];
__block UIImage *shareImage;
PHImageRequestOptions* options = [[PHImageRequestOptions alloc]init];
options.resizeMode = PHImageRequestOptionsResizeModeExact;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.version = PHImageRequestOptionsVersionUnadjusted;
options.synchronous = YES;
[[PHImageManager defaultManager] requestImageForAsset:lastAsset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:PHImageRequestOptionsVersionCurrent
resultHandler:^(UIImage *result, NSDictionary *info) {
dispatch_async(dispatch_get_main_queue(), ^{
shareImage = result;
[items addObject:shareImage]; });
}];
NSMutableArray *activityItems = [NSMutableArray arrayWithArray:items];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityViewController animated:YES completion:nil];
任何帮助将不胜感激。我是 iOS 开发和编程的新手,我一直很难用这个。
谢谢