我正在为 iOS 制作一个包含照片元数据的相机应用程序。我使用资产库来编写元数据。“writeImageDataToSavedPhotoAlbum”方法有一个返回资产 URL 的完成块。我假设我需要保存此 URL,以便检索元数据和图像。但是,我似乎无法弄清楚如何处理assetURL,以便获取我的信息。
我的代码:
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeMovie]){
NSURL *urlOfVideo = [info objectForKey:UIImagePickerControllerMediaURL];
} else if ([mediaType isEqualToString:(__bridge NSString *)kUTTypeImage]) {
CLLocation *location = [[CLLocation alloc] init];
NSDictionary *metadata = [self getGPSDictionaryForLocation:location];
UIImage *theImage = [info objectForKey:UIImagePickerControllerOriginalImage];
ALAssetsLibrary* library = [[ALAssetsLibrary alloc] init];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(theImage)];
[library writeImageDataToSavedPhotosAlbum:imageData metadata:metadata completionBlock:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"error");
} else {
////what do I do with the assetURL?
self.imageURL = assetURL;
NSLog(@"url %@", self.imageURL);
}
} ];
}
[picker dismissViewControllerAnimated:YES completion:nil];
}