Save image to photo library using photo framework

前端 未结 4 604
眼角桃花
眼角桃花 2020-12-16 00:51

My app crashes every time when I try to save image using photo framework.

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMedi         


        
4条回答
  •  没有蜡笔的小新
    2020-12-16 01:24

    1. delete third line of the code
    2. Verify that the _mChangeRequest is __block variable
    3. compile and run

    you will see that image in the photos app

    you will change code probably like this...

    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    
      __block PHAssetChangeRequest *_mChangeRequest = nil;
    
      [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    
      _mChangeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[info valueForKey:UIImagePickerControllerOriginalImage]];
    
      } completionHandler:^(BOOL success, NSError *error) {
    
          if (success) {
    
              PHObjectPlaceholder *assetPlaceholder = _mChangeRequest.placeholderForCreatedAsset;
          }
          else {
    
             NSLog(@"write error : %@",error);
          }
    }];
    }
    

提交回复
热议问题