【问题标题】:Ionic get all thumbnails from camera roll离子从相机胶卷中获取所有缩略图
【发布时间】:2016-12-23 03:59:30
【问题描述】:

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

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

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

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

** 构建失败 **

以下构建命令失败: ld build/emulator/.app/ normal i386 (1 次失败) 命令的错误代码 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 上工作,或者建议另一个插件,将不胜感激。

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

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

}

谢谢

【问题讨论】:

    标签: ios objective-c cordova ionic-framework camera-roll


    【解决方案1】:

    感谢您的帮助。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多