I'm trying to add some functionality to Narek Adonts ALAssets wrapper:
https://www.b4x.com/android/forum/threads/alassets-wraps-the-native-alassets-framework-photos.65231/
I want to get the SaveBitmapToAlbum objective C to return the internal asset object it generates.
If I do this then I will be able to maintain an external "photo name" vs "asset object" table and hence have much greater control over the albums etc.
The following is a slightly modified form of the original which compiles OK:
and the NSLog(@"Added %@", asset); line is logging what I am trying to extract.
My attempt at modifying the code is:
I have only changed 3 lines, all with the //jk comment.
This bombs at the line:
resultBlock:^(ALAsset* asset) {
with this error message:
and several other warnings.
I suspect I am doing something very stupid - all help appreciated.
https://www.b4x.com/android/forum/threads/alassets-wraps-the-native-alassets-framework-photos.65231/
I want to get the SaveBitmapToAlbum objective C to return the internal asset object it generates.
If I do this then I will be able to maintain an external "photo name" vs "asset object" table and hence have much greater control over the albums etc.
The following is a slightly modified form of the original which compiles OK:
B4X:
-(void)SaveBitmapToAlbum :(ALAssetsGroup*)group :(UIImage*)image
{
CGImageRef img = [image CGImage];
ALAssetsLibrary *library = [self defaultAssetsLibrary] ;
[library writeImageToSavedPhotosAlbum:img
metadata:nil
completionBlock:^(NSURL* assetURL, NSError* error) {
if (error.code == 0) {
NSLog(@"saved image completed:\nurl: %@", assetURL);
// try to get the asset
ALAssetsLibrary *library = [self defaultAssetsLibrary] ;
[library assetForURL:assetURL
resultBlock:^(ALAsset* asset) {
// assign the photo to the album
[group addAsset:asset];
NSLog(@"Added %@", asset);
}
failureBlock:^(NSError* error) {
NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
}];
}
else {
NSLog(@"saved image failed.\nerror code %i\n%@", error.code, [error localizedDescription]);
}
}];
}
and the NSLog(@"Added %@", asset); line is logging what I am trying to extract.
My attempt at modifying the code is:
B4X:
//jk
-(ALAsset*)SaveBitmapToAlbum :(ALAssetsGroup*)group :(UIImage*)image
{
CGImageRef img = [image CGImage];
ALAssetsLibrary *library = [self defaultAssetsLibrary] ;
[library writeImageToSavedPhotosAlbum:img
metadata:nil
completionBlock:^(NSURL* assetURL, NSError* error) {
if (error.code == 0) {
NSLog(@"saved image completed:\nurl: %@", assetURL);
// try to get the asset
ALAssetsLibrary *library = [self defaultAssetsLibrary] ;
[library assetForURL:assetURL
resultBlock:^(ALAsset* asset) {
// assign the photo to the album
[group addAsset:asset];
NSLog(@"Added %@", asset);
//jk
return asset;
}
failureBlock:^(NSError* error) {
NSLog(@"failed to retrieve image asset:\nError: %@ ", [error localizedDescription]);
}];
}
else {
NSLog(@"saved image failed.\nerror code %i\n%@", error.code, [error localizedDescription]);
}
}];
//jk
return nil;
}
I have only changed 3 lines, all with the //jk comment.
This bombs at the line:
resultBlock:^(ALAsset* asset) {
with this error message:
/Users/administrator/Documents/UploadedProjects/<user id>/B4iProject/b4i_alassets.m:388:36: error: incompatible block pointer types sending 'ALAsset *(^)(ALAsset *__strong)' to parameter of type 'ALAssetsLibraryAssetForURLResultBlock' (aka 'void (^)(ALAsset *__strong)')
resultBlock:^(ALAsset* asset) {
^~~~~~~~~~~~~~~~~~~
and several other warnings.
I suspect I am doing something very stupid - all help appreciated.