简体   繁体   English

AssetsLibrary:定位服务提示。 Instagram如何避免这种情况?

[英]AssetsLibrary: Location Services prompt. How did Instagram avoid it?

I am working an app that uses the photos and videos in the AssetsLibrary, and I am just trying to determine once and for all if there is any way around asking the user for permission to access Location data in order to get these assets. 我正在使用一个使用AssetsLibrary中的照片和视频的应用程序,而我只是想一劳永逸地确定是否有任何办法可以要求用户允许访问位置数据以获取这些资产。 I understand that the EXIF data includes GPS information, and that makes enough sense to me. 我了解EXIF数据包含GPS信息,这对我来说足够有意义。

Note: I have searched through StackOverflow and I have found similar questions, and I am not making this post simply to add one more to the list. 注意:我搜索了StackOverflow,发现了类似的问题,我在此发布的目的并非仅仅是在列表中添加一个。 I am asking specifically about one (apparent) counterexample. 我专门询问一个(明显的)反例。

When using Instagram for the first time, I am able to browse through my photo album, select photos, edit them and share them all without ever being prompted about location services. 首次使用Instagram时,我可以浏览我的相册,选择照片,对其进行编辑并共享它们,而无需任何有关位置服务的提示。 I am only prompted when I choose to click on the button labeled "Enable Geotagging." 仅当我选择单击标记为“启用地理标记”的按钮时,系统才会提示我。 Checking the settings tab, it looks like if I don't ever click that button, Instagram doesn't even come up in the Location Services section of my Settings. 检查设置选项卡,好像我从未单击过该按钮,Instagram甚至没有出现在“设置”的“位置服务”部分中。

My question is, how did Instagram get away with this? 我的问题是,Instagram如何摆脱这种情况? Anyone have any ideas? 有人有想法么? I'd like to figure out if I can mimic their implementation somehow so my users aren't shut out from getting their camera assets if they say no to this prompt. 我想弄清楚我是否可以模仿他们的实现方式,这样如果我的用户对此提示说“不”,那么我的用户就不会被排斥在外。

the explanation is quite simple. 解释很简单。 Instagram uses the UIImagePickerController. Instagram使用UIImagePickerController。 UIImagePickerController works without Location Services enabled, but you don't get EXIF data using this method. UIImagePickerController可以在未启用定位服务的情况下工作,但是您无法使用此方法获取EXIF数据。 UIImagePickerController can retrieve metadata (incl. GPS) only through the UIImagePickerControllerReferenceURL. UIImagePickerController只能通过UIImagePickerControllerReferenceURL检索元数据(包括GPS)。 UIImagePickerControllerReferenceURL you have to pass then AssetsLibrary methods, which needs again location services enabled. 您必须先传递UIImagePickerControllerReferenceURL,然后再传递AssetsLibrary方法,这需要再次启用位置服务。 Cheers, 干杯,

Hendrik 亨德里克

As holtmann mentioned, reading the UIImagePickerControllerReferenceURL triggers the location services prompt. 如holtmann所述,读取UIImagePickerControllerReferenceURL会触发位置服务提示。 If you only need the image data, not the metadata, you can get that from the UIImagePickerControllerOriginalImage and UIImagePickerControllerEditedImage keys instead (I'm checking EditedImage first and then checking OriginalImage if EditedImage is null). 如果只需要图像数据,而不是元数据,则可以从UIImagePickerControllerOriginalImage和UIImagePickerControllerEditedImage键中获取(我先检查EditedImage,然后如果EditedImage为null则检查OriginalImage)。 This doesn't require the use of the assets library and doesn't require location access. 这不需要使用资产库,也不需要位置访问。

Here's how I'm using this in my app, including saving a local copy of the image for further editing: 这是我在应用程序中使用它的方式,包括保存图像的本地副本以供进一步编辑:

- (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];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM