Saving image using Photos.Framework performChanges application crashing

I am using uiimagepickercontroller to get photos from the camera and then the following function is called. When the executeChanges block is called, there is a spike in memory usage and if many photos are executed quickly, the application crashes. Also, not all photos are saved.

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
     UIImage* originalImage =[info objectForKey:UIImagePickerControllerOriginalImage];

     CGSize destinationSize = self.shutterButton.frame.size;
     UIGraphicsBeginImageContext(destinationSize);
     [originalImage drawInRect:CGRectMake(0,0,destinationSize.width,destinationSize.height)];
     UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
     UIGraphicsEndImageContext();

     [self.shutterButton setBackgroundImage:newImage forState:UIControlStateNormal];
    //[self saveImage:originalImage];
    [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetChangeRequest *assetChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:newImage];

        //the if statement below should be:if (self.assetCollection)
        if (self.assetCollection) {
            PHAssetCollectionChangeRequest *assetCollectionChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:self.assetCollection];
            [assetCollectionChangeRequest addAssets:@[[assetChangeRequest placeholderForCreatedAsset]]];
        }
    } completionHandler:^(BOOL success, NSError *error) {
        if (!success) {
            NSLog(@"Error creating asset: %@", error);
        }
    }];
}

      

+3
ios objective-c ios8 uiimagepickercontroller


source to share


No one has answered this question yet

Check out similar questions:

958
How do I change the name of an iOS app?
680
How to connect to apps in the app store
273
UIActivityViewController error on iOS 8 iPads
0
NSLog fails
0
UIImagePickerController removeModalViewController
0
Printing with Zebra ZQ520 "Rotation causes problems"
0
accessing ext from UIImagePickerControllerReferenceURL
0
iOS: how to change between views after selecting photos?
0
Why was this object released?
-2
Getting ALASset object from camera



All Articles
Loading...
X
Show
Funny
Dev
Pics