I'm building an app where the user needs to be able to select photos from their camera roll
I know I can use the cordova-camera pluggin for selecting one photo at a time or the cordova-imagePicker plugin for selecting multiple photos, but I want a I want a custom feel where you can see all images in app.
On Android I used the cordova-gallery-api plugin, the app felt a little choppy with the full sized images but works great with the thumbnails.
When I tried the Gallery API on IOS, with the plugin installed, the build failed with
** BUILD FAILED **
The following build commands failed: Ld build/emulator/.app/ normal i386 (1 failure) Error code 65 for command: xcodebuild with args: -xcconfig,/platforms/ios/cordova/build-debug.xcconfig,-project,.xcodeproj,ARCHS=i386,-target,,-configuration,Debug,-sdk,iphonesimulator,build,VALID_ARCHS=i386,CONFIGURATION_BUILD_DIR=/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/platforms/ios/build/sharedpch ERROR building one of the platforms: Error: /platforms/ios/cordova/build: Command failed with exit code 2 You may not have the required environment or OS to build this project Error: /platforms/ios/cordova/build: Command failed with exit code 2
Earlier I found cordova-camera-roll plugin which looked to do the same thing but only for IOS. I tried it out, it works; however, it only returns the full sized images which feel choppy when scrolling.
Both the plugins I've tried are relatively old and I don't have much experience with Objective-C, If you could help alter the camera roll plugin to return thumbnails, or get the gallery plugin to work on IOS, or suggest another plugin it would be greatly appreciated.
PS. for easy of use, the Camera Roll function
- (void)getPhotos:(CDVInvokedUrlCommand*)command
{
// Grab the asset library
ALAssetsLibrary *library = [IonicCameraRoll defaultAssetsLibrary];
// Run a background job
[self.commandDelegate runInBackground:^{
// Enumerate all of the group saved photos, which is our Camera Roll on iOS
[library enumerateGroupsWithTypes:ALAssetsGroupSavedPhotos usingBlock:^(ALAssetsGroup *group, BOOL *stop) {
// When there are no more images, the group will be nil
if(group == nil) {
// Send a null response to indicate the end of photostreaming
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:nil];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} else {
// Enumarate this group of images
[group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
NSDictionary *urls = [result valueForProperty:ALAssetPropertyURLs];
[urls enumerateKeysAndObjectsUsingBlock:^(id key, NSURL *obj, BOOL *stop) {
// Send the URL for this asset back to the JS callback
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsString:obj.absoluteString];
[pluginResult setKeepCallbackAsBool:YES];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
} failureBlock:^(NSError *error) {
// Ruh-roh, something bad happened.
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:error.localizedDescription];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}];
}
Thanks
Thanks for the help.
The gallery-api worked fine as is, it just needed me to Enable Modules in Xcode