【发布时间】:2015-07-01 20:45:46
【问题描述】:
我正在使用 Xcode Simulator 版本 8.2(最新)测试我的应用程序。当用户选择照片时,我的代码使用 ALAssetsLibrary 提取 CLocation 信息。特别是属性 ALAssetPropertyLocation。
我该如何测试呢?我知道如何将照片添加到模拟器。我用我的 iPhone 拍了一张照片,然后通过将照片拖放到模拟器上,将其放入模拟器的相机胶卷中。在将照片放入模拟器之前,我还验证了它具有 EXIF 位置数据。
代码看起来正确,但我猜照片的元数据可能存储在其他地方,简单地将照片复制到模拟器上不会创建 CLocation 信息。
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([picker sourceType] == UIImagePickerControllerSourceTypePhotoLibrary) {
// We'll store the info to use in another function later
self.selectedPhotoInfo = info;
// Get picked image from info dictionary
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// Get the asset url
NSURL *url = [info objectForKey:UIImagePickerControllerReferenceURL];
// We need to use blocks. This block will handle the ALAsset that's returned:
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
// Get the location property from the asset
CLLocation *location = [myasset valueForProperty:ALAssetPropertyLocation];
// call image location handler
[self handleImageLocation:location];
};
// This block will handle errors:
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Can not get asset - %@",[myerror localizedDescription]);
// Do something to handle the error
};
// Use the url to get the asset from ALAssetsLibrary,
// the blocks that we just created will handle results
ALAssetsLibrary* assetslibrary = [[ALAssetsLibrary alloc] init];
[assetslibrary assetForURL:url
resultBlock:resultblock
failureBlock:failureblock];
}
【问题讨论】:
-
发布一些代码怎么样?
标签: ios objective-c ios-simulator photo alassetslibrary