Closed AshStill closed 8 years ago
I think in ios8 , PHPhotolibrary should be an option to use https://developer.apple.com/library/ios/documentation/Photos/Reference/PHPhotoLibrary_Class/index.html#//apple_ref/doc/uid/TP40014404
@AshStill yup, u do need to import Photos framework for ur project since iOS 8.
@Kjuly I have imported Photos framework in my project and sometimes still fail when save asset to savedAlbum especially when updated to iOS8.4.1.
Hey @AshStill, what's the fail error that u got? I'll debug to c anything wrong w/ the new version when got time, pretty busy these days. sorry for that.
@Kjuly I find an solution for these. I will make pull request once I've done.
@Kjuly I think i finished with PHPhotoLibrary but the problem is that I can't return an assetUrl, because PHAsset has its own identifier but not assetUrl :sob:
@AshStill, sorry, still don't have time to take a look at it yet, will check it around this weekend. :)
Hi @AshStill , i tried on iOS 8.4.1, w/o any issue, even tried to delete the album first. Several questions need ur help to answer:
-saveImage:toAlbum:completion:failure
:completion
block invoked before u trying to show the photo? (Make sure the photo was saved exactally before using it, or u can use the cached original photo while in saving process.)failure
block is invoked? If it is, what's the detail error? -assetForURL:resultBlock:failureBlock:
's failureBlock
?B.t.w., it'll be good if u offer some code snippets. :)
@Kjuly In my case, in the following function, the asset is nil, so it leads to the failure block _assetForURLResultBlockWithGroup:assetURL:completion:failure:
I use following code in ios8 in my case.
-(void)performSaveImage:(UIImage*)image toAlbum:(NSString*)name completionHandler:(void(^)(BOOL success, NSError *error))completionHandler
{
PHFetchOptions *options = [[PHFetchOptions alloc] init];
options.predicate = [NSPredicate predicateWithFormat:@"title = %@" , name];
__block PHAssetCollection *album = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:options].firstObject;
if (!album)
{
[[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
[PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:name];
} error:nil];
album = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:options].firstObject;
}
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
// Request creating an asset from the image.
PHAssetChangeRequest *createAssetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:image];
// Request editing the album.
PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:album];
// Get a placeholder for the new asset and add it to the album editing request.
PHObjectPlaceholder *assetPlaceholder = [createAssetRequest placeholderForCreatedAsset];
[albumChangeRequest addAssets:@[ assetPlaceholder ]];
} completionHandler:^(BOOL success, NSError *error) {
if (completionHandler) {
completionHandler(success,error);
}
}];
}
In my case, in the following function, the asset is nil, so it leads to the failure block _assetForURLResultBlockWithGroup:assetURL:completion:failure:
Which one, L157 or L181? And what's the assetURL
u were trying to save?
B.t.w., can u try the latest code's demo? Let's c whether it works in ur environ.
YEP,I have the same question . when debug in L157 or L181 ,it works ok . without breakpoint it will filled in L181 [group addAsset:asset] with asset is nil Sorry for my poor English
@Onion520
without breakpoint it will filled in L181 [group addAsset:asset] with asset is nil
Seems asset cannot be found.
What's the value of assetURL
in L185 for ur case?
assetURL : assets-library://asset/asset.mov?id=C10AB3B5-EE07-4D12-A4DD-14E976FA854E&ext=mov
when put a breakpoint in L157 or L181 the move can be save ok . And This is only on my cell phone。 other phone didn't have the question @Kjuly
this function sometime return nil, which will lead the saveimage to failureblock.