0

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

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

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

当我在 IOS 上尝试安装插件的 Gallery API 时,构建失败

** 构建失败 **

以下构建命令失败:Ld build/emulator/.app/ normal i386 (1 failure) 命令错误代码 65: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 错误构建一个平台:错误:/platforms/ios/cordova/build:命令失败,退出代码 2 您可能没有构建此项目所需的环境或操作系统错误:/platforms/ios/cordova/build:命令失败,退出代码2

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

我试过的两个插件都比较老,我对 Objective-C 没有太多经验,如果你能帮助改变相机胶卷插件以返回缩略图,或者让画廊插件在 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];
    }];
  }];

}

谢谢

4

1 回答 1

0

谢谢您的帮助。

Gallery-api工作正常,只需要我在 Xcode 中启用模块

于 2016-08-17T16:23:49.263 回答