###前提・実現したいこと
Objective-cでiPadアプリを作成しています。
標準カメラを使用して撮った写真に位置情報を付与して保存しようしたところ、
写真にメタデータを付与するところでエラーが発生しました。
###発生している問題・エラーメッセージ
2017-08-19 07:37:12.742 xxxxxApp[505:166141] Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates. warning: could not execute support code to read Objective-C class data in the process. This may reduce the quality of type information available. 2017-08-19 07:37:40.488 xxxxxApp[505:166141] -[__NSDictionaryI setObject:forKeyedSubscript:]: unrecognized selector sent to instance 0x1750c1f0 2017-08-19 07:37:40.494 xxxxxApp[505:166141] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI setObject:forKeyedSubscript:]: unrecognized selector sent to instance 0x1750c1f0' *** First throw call stack: (0x245db91b 0x23d76e17 0x245e12b5 0x245deee1 0x2450a238 0x24a93 0x28ff0693 0x2e001e7b 0x2e0169bb 0x2e047a2b 0x2c0c7117 0x162e39 0x155b6b 0x15a655 0x2459db6d 0x2459c067 0x244eb229 0x244eb015 0x25adbac9 0x28bbf189 0x23907 0x24193873) libc++abi.dylib: terminating with uncaught exception of type NSException
###該当のソースコード
こちらのサイトを参考にさせて頂きました。→http://dev.classmethod.jp/smartphone/iphone/uiimagepickercontroller-exifgps/
サンプルソースも実行したところ同様のエラーが発生しました。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { // モーダルビューを閉じる [self dismissViewControllerAnimated:YES completion:nil]; // 静止画の参照を取得 UIImage *image = info[UIImagePickerControllerOriginalImage]; // カメラを起動した場合、カメラロールに保存する。 if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { // メタデータの参照を取得 NSMutableDictionary *metadata = info[UIImagePickerControllerMediaMetadata]; // この行でエラーが発生します。↓↓ metadata[(NSString *)kCGImagePropertyGPSDictionary] = [self GPSDictionaryForLocation:self.locationManager.location]; // カメラロールに保存 ALAssetsLibrary *assetsLibrary = [[ALAssetsLibrary alloc] init]; [assetsLibrary writeImageToSavedPhotosAlbum:image.CGImage metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error) { if (error) { NSLog(@"Save image failed. %@", error); } }]; [self dismissViewControllerAnimated:YES completion:nil]; } // イメージビューに写真を表示する。 _editImageView.image = image; // 次画面に渡すキャプションを設定 [Image sharedManager].image = image; } // GPS情報の作成 - (NSDictionary *)GPSDictionaryForLocation:(CLLocation *)location { NSMutableDictionary *gps = [NSMutableDictionary new]; // 日付 gps[(NSString *)kCGImagePropertyGPSDateStamp] = [[FormatterUtil GPSDateFormatter] stringFromDate:location.timestamp]; // タイムスタンプ gps[(NSString *)kCGImagePropertyGPSTimeStamp] = [[FormatterUtil GPSTimeFormatter] stringFromDate:location.timestamp]; // 緯度 CGFloat latitude = location.coordinate.latitude; NSString *gpsLatitudeRef; if (latitude < 0) { latitude = -latitude; gpsLatitudeRef = @"S"; } else { gpsLatitudeRef = @"N"; } gps[(NSString *)kCGImagePropertyGPSLatitudeRef] = gpsLatitudeRef; gps[(NSString *)kCGImagePropertyGPSLatitude] = @(latitude); // 経度 CGFloat longitude = location.coordinate.longitude; NSString *gpsLongitudeRef; if (longitude < 0) { longitude = -longitude; gpsLongitudeRef = @"W"; } else { gpsLongitudeRef = @"E"; } gps[(NSString *)kCGImagePropertyGPSLongitudeRef] = gpsLongitudeRef; gps[(NSString *)kCGImagePropertyGPSLongitude] = @(longitude); // 標高 CGFloat altitude = location.altitude; if (!isnan(altitude)){ NSString *gpsAltitudeRef; if (altitude < 0) { altitude = -altitude; gpsAltitudeRef = @"1"; } else { gpsAltitudeRef = @"0"; } gps[(NSString *)kCGImagePropertyGPSAltitudeRef] = gpsAltitudeRef; gps[(NSString *)kCGImagePropertyGPSAltitude] = @(altitude); } return gps; }
###試したこと
- NSInvalidArgumentExceptionでググったものの解決には至りませんでした。Objective-C、iOSについては疎いため、見るべきところ、調べる方法など知識不足です。申し訳ありません。質問について情報が不足している場合は追記いたします。
###補足情報(言語/FW/ツール等のバージョンなど)
- Version 8.3.3 (8E3004b)
- iOS 9.3.5
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。