Chr*_*ina 7 iphone cocoa-touch ios4 ios alasset
可能重复:
我如何避免AlAssetLibrary中的位置服务?我可以使用AlAssetLibrary检索文件而无需使用位置服务吗?
大家好,我是iphone开发和obj-c的新手.我在我的应用程序中使用"ALAssetLibrary"从照片库中检索图像.我发现只有在为调用者启用了位置服务时," ALAssetPropertyLocation "属性键才可用.它是检索资产的位置信息的关键.但我没有使用"ALAssetPropertyLocation"Property.i我只使用ALAssetPropertyURLs.
每当我尝试在新设备中部署我的应用程序时,都会出现一个消息框,其中显示消息"需要位置服务.."我可以隐藏"ALAssetPropertyLocation"属性吗?
我真的很感激,如果有人能以正确的方式帮助我解决我的问题,并且如果可能的话,可以使用任何示例代码来启动我的问题.
先感谢您 :)
这是我的代码:
//Getting image url from dictionary according to the user input
NSURL *imageurl = [dict objectForKey: [youSaid text]];
//Getting asset from url
typedef void (^ALAssetsLibraryAssetForURLResultBlock)(ALAsset *asset);
typedef void (^ALAssetsLibraryAccessFailureBlock)(NSError *error);
ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *myasset)
{
ALAssetRepresentation *rep = [myasset defaultRepresentation];
CGImageRef iref = [rep fullResolutionImage];
//Setting asset image to image view according to the image url
[imageview setImage:[UIImage imageWithCGImage:iref]];
};
ALAssetsLibraryAccessFailureBlock failureblock = ^(NSError *myerror)
{
NSLog(@"Error, cant get image - %@",[myerror localizedDescription]);
};
if(imageurl != nil)
{
ALAssetsLibrary *assetLibrary=[[ALAssetsLibrary alloc] init];
[assetLibrary assetForURL:imageurl resultBlock:resultblock failureBlock:failureblock];
}
Run Code Online (Sandbox Code Playgroud)
启用"位置服务"是使用AssetsLibrary的要求.原因是Photo-Library中的任何照片/视频可能包含地理数据.此数据不仅可通过ALAssetPropertyURLs获得,而且还可以从资产中读取原始数据(通过使用getBytes:fromOffset:length:error:ALAssetsRepresentation方法).因为无法从原始图像数据中剥离地理元数据(如果禁用了位置服务),我想设计决策是为了使"AssetsLibrary"必须使用"位置服务".
此要求可能会使用户感到困惑.所以你需要做两件事:
1)如果用户拒绝访问位置服务,则在您的应用需要此访问权限时显示清除消息,并且该应用实际上并未确定当前位置或任何GPS /数据.
2)一旦用户在初始对话框上按"否",显示如何启用位置服务的清晰说明.
干杯,
亨德里克