私のアプリケーションでは、保存している画像がフォト アルバムに書き込まれ始め、Photos アプリケーションで適切に表示されることに気付きました。しかし、新しい画像をコピーした元の画像を削除すると、新しい画像のサムネイルが消えてしまいます。それは本当に奇妙です。
アセット ライブラリに保存する CGImageRef を作成するために使用するコードは次のとおりです。
NSDictionary *options = [NSDictionary
dictionaryWithObjectsAndKeys:(__bridge NSNumber *)kCFBooleanTrue,
(__bridge NSString *)kCGImageSourceCreateThumbnailFromImageAlways, nil];
CGImageRef fullImage = [asset.defaultRepresentation CGImageWithOptions:options];
以前は、defaultRepresentation.fullResolution 画像を取得してアセット ライブラリに書き込んでいただけです。
私の質問は次のとおりです。この方法で画像を保存することで、期待するサムネイルが作成されますか? そうでない場合は、サムネイルを作成して「消え」ないようにするために別のことをする必要があります。
編集:これが発生したときのコンソールのエラーは次のとおりです。
Aug 18 11:08:27 [phone name] [app name][2081] <Error>: Fixing thumbnail for 0x112b2dc0 <x-coredata://97C87589-EC35-4664-BE0D-AD01687EF7C4/Asset/p3637> AF6CD736-EF5D-482A-AFAD-F12834C301BF at index 2
失敗したサムネイルの修復は、GPS ディクショナリを新しい座標で変更している画像に対してのみ発生するようです。座標を削除した画像では、サムネイルが正しく修復されています。
そのセクションのコードは次のとおりです。
NSDictionary *gpsDictionary =
[readOnlyMetadata valueForKey:(__bridge NSString*) kCGImagePropertyGPSDictionary];
NSMutableDictionary *modifiableGpsDictionary = (gpsDictionary) ?
[gpsDictionary mutableCopy] : [[NSMutableDictionary alloc] init];
CLLocationCoordinate2D coordinate = thumbnail.coordinate;
[modifiableGpsDictionary setValue:[NSNumber numberWithDouble:ABS(coordinate.latitude)]
forKey:(__bridge NSString*) kCGImagePropertyGPSLatitude];
[modifiableGpsDictionary setValue:(coordinate.latitude < 0.0) ? @"S" : @"N"
forKey:(__bridge NSString*) kCGImagePropertyGPSLatitudeRef];
[modifiableGpsDictionary setValue:[NSNumber numberWithDouble:ABS(coordinate.longitude)]
forKey:(__bridge NSString*) kCGImagePropertyGPSLongitude];
[modifiableGpsDictionary setValue:(coordinate.longitude < 0.0) ? @"W" : @"E"
forKey:(__bridge NSString*) kCGImagePropertyGPSLongitudeRef];
[modifiableMetadata setValue:modifiableGpsDictionary
forKey:(__bridge NSString*) kCGImagePropertyGPSDictionary];