All you need to do is trigger a creation request. As the error says, you can access the change request only inside the performChanges
block.
So to save the image you would do something like this:
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
[PHAssetChangeRequest creationRequestForAssetFromImage:[info valueForKey:UIImagePickerControllerOriginalImage]];
} completionHandler:^(BOOL success, NSError *error) {
if (success) {
NSLog(@"Success");
}
else {
NSLog(@"write error : %@",error);
}
}];
In case you need to do something with the placeholder of the newly created asset, you can access it inside the same performChanges
block:
PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[info valueForKey:UIImagePickerControllerOriginalImage]];
PHObjectPlaceholder *assetPlaceholder = changeRequest.placeholderForCreatedAsset;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…