ユーザーがカメラロールから写真を選択できるようにする必要があるアプリを構築しています
一度に 1 枚の写真を選択するために 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 エラー ビルド 1エラー: /platforms/ios/cordova/build: コマンドが終了コード 2 で失敗しました このプロジェクトをビルドするために必要な環境または OS がない可能性があります エラー: /platforms/ios/cordova/build: コマンドが終了コードで失敗しました2
以前に、同じことを行うように見えたがIOS専用のcordova-camera-rollプラグインを見つけました。試してみましたが、うまくいきます。ただし、スクロールすると途切れ途切れに感じるフルサイズの画像のみが返されます。
私が試したプラグインはどちらも比較的古く、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];
}];
}];
}
ありがとう