I want to fetch the last photo taken in the photoLibrary and add it to an array which will be used in the UIActivivtyViewController. When the UIActivityViewController is presented, the image is not shown and it appears that the UIImage was never added to the array.
Here is what I have,
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];
Any help will be appreciated. I am new to to iOS dev and programming all together and I have been having a very hard time with this one.
Thanks