使用Photos.Framework保存图像performChanges会崩溃应用程序

时间:2014-11-17 17:47:30

标签: ios objective-c ios8 uiimagepickercontroller

我正在使用uiimagepickercontroller从相机中获取照片,然后调用以下函数。当调用performChanges块时,内存使用量会出现峰值,如果快速连续拍摄很多照片,应用程序会崩溃。此外,并非所有照片都已保存。

-(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);
        }
    }];
}

0 个答案:

没有答案