Bhagyashree mahajan Bhagyashree mahajan - 1 year ago 99
iOS Question

iOS: Get last image from the camera roll

I want the last image saved in camera roll.
I have searched for it but m getting result for ALAssetsLibrary which is deprecated in iOS 9 so please provide me solution for this because m not getting proper solution for that.

I want solution in objective C.

Answer Source

Please check this code... it may help you.

PHFetchOptions *fetchOptions = [[PHFetchOptions alloc] init];
fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
PHFetchResult *fetchResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:fetchOptions];
PHAsset *lastAsset = [fetchResult lastObject];
[[PHImageManager defaultManager] requestImageForAsset:lastAsset
                                       resultHandler:^(UIImage *result, NSDictionary *info) {

                                           dispatch_async(dispatch_get_main_queue(), ^{

                                               [[self photoLibraryButton] setImage:result forState:UIControlStateNormal];

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download