我正在开发一个使用AssetsLibrary中的照片和视频的应用程序,我只是想一劳永逸地确定是否有任何方法可以绕过请求用户访问位置数据的权限,以便获得这些资产。我知道EXIF数据包括GPS信息,这对我来说很有意义。
注意:我已经在StackOverflow上搜索过了,我发现了类似的问题,我写这篇文章并不是为了在列表中再增加一个。我特别问的是一个(明显的)反例。
当我第一次使用Instagram时,我能够浏览我的相册,选择照片,编辑它们,并将它们全部分享,而从来没有关于位置服务的提示。只有当我选择单击标记为“启用地理标记”的按钮时,系统才会提示我。检查设置选项卡,如果我从来没有点击过那个按钮,Instagram甚至不会出现在我的设置的位置服务部分。
我的问题是,Instagram是如何逃脱惩罚的?有谁有什么想法吗?我想知道我是否可以以某种方式模仿他们的实现,这样如果我的用户对这个提示说不,他们就不会被拒之门外。
发布于 2012-01-16 19:26:14
解释很简单。Instagram使用的是UIImagePickerController。UIImagePickerController在没有启用位置服务的情况下工作,但您不能使用此方法获取数据。UIImagePickerController可以检索元数据(包括全球定位系统)只能通过UIImagePickerControllerReferenceURL。你必须传递AssetsLibrary方法,这需要再次启用位置服务。干杯,
亨德里克
发布于 2012-05-31 01:56:57
正如霍尔特曼提到的,读取UIImagePickerControllerReferenceURL会触发定位服务提示。如果您只需要图像数据,而不是元数据,那么您可以从UIImagePickerControllerOriginalImage和UIImagePickerControllerEditedImage键获取(如果EditedImage为null,我将首先检查EditedImage,然后检查OriginalImage )。这不需要使用资源库,也不需要位置访问。
以下是我如何在我的应用程序中使用它,包括保存图像的本地副本以供进一步编辑:
- (void)imagePickerController:(UIImagePickerController *)controller didFinishPickingMediaWithInfo:(NSDictionary *)info {
// get the selected photo as a UIImage
UIImage *photo = [info objectForKey:@"UIImagePickerControllerEditedImage"];
if (!photo) {
photo = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
}
// save the photo to the app's Documents folder
if (photo) {
NSString *extension = @"jpg";
NSString *filename = [NSString stringWithFormat:@"%@.%@", self.defaultTitle, extension]; // self.defaultTitle is defined elsewhere in my app
NSString *path = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:filename];
[UIImageJPEGRepresentation(photo, 0.8) writeToFile:path atomically:YES];
}
}https://stackoverflow.com/questions/8859164
复制相似问题