Ionic 从相机胶卷中获取所有缩略图

Ionic get all thumbnails from camera roll

我正在构建一个应用程序,用户需要能够从他们的相机胶卷select照片

我知道我可以使用 cordova-camera 插件一次 select 拍摄一张照片,或者使用 cordova-imagePicker 插件 select 拍摄多张照片,但我想要一张我想要一张自定义感觉,您可以在其中查看应用程序中的所有图像。

在 Android 上,我使用了 cordova-gallery-api 插件,该应用程序对全尺寸图像感觉有点不稳定,但对缩略图效果很好。

当我在 IOS 上尝试图库 API 时,安装了插件,构建失败

** 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

早些时候我发现 cordova-camera-roll 插件看起来做同样的事情但只适用于 IOS。我试过了,它有效;然而,它只是 return 滚动时感觉不稳定的全尺寸图像。

我试过的两个插件都比较老,我对Objective-C没有太多经验,如果你能帮忙把相机胶卷插件改成return缩略图,或者得到gallery 插件可以在 IOS 上工作,或者建议另一个插件,我们将不胜感激。

PS。 为了方便使用,相机胶卷功能

- (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];
    }];
  }];

}

谢谢

感谢您的帮助。

gallery-api 工作正常,它只需要我在 Xcode

中启用模块