AssetsLibrary:位置服务提示。 Instagram 是如何避免这种情况的呢?

发布于 2024-12-27 02:57:20 字数 451 浏览 1 评论 0原文

我正在开发一个使用 AssetsLibrary 中的照片和视频的应用程序,我只是想一劳永逸地确定是否有任何方法可以询问用户访问位置数据的权限以获得这些资产。我知道 EXIF 数据包含 GPS 信息,这对我来说很有意义。

注意:我在 StackOverflow 中进行了搜索,发现了类似的问题,我发表这篇文章并不是为了在列表中再添加一个问题。我具体询问一个(明显的)反例。

当我第一次使用 Instagram 时,我可以浏览我的相册、选择照片、编辑它们并分享它们,而不会收到关于位置服务的提示。仅当我选择单击标有“启用地理标记”的按钮时才会出现提示。检查“设置”选项卡,看起来如果我不单击该按钮,Instagram 甚至不会出现在我的“设置”的“位置服务”部分中。

我的问题是,Instagram 是如何逃脱惩罚的呢?有人有什么想法吗?我想知道是否可以以某种方式模仿他们的实现,这样如果我的用户拒绝此提示,他们就不会被拒绝获取他们的相机资产。

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. I understand that the EXIF data includes GPS information, and that makes enough sense to me.

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. 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. 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.

My question is, how did Instagram get away with this? 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我还不会笑 2025-01-03 02:57:21

解释很简单。 Instagram 使用 UIImagePickerController。 UIImagePickerController 在未启用位置服务的情况下工作,但使用此方法无法获取 EXIF 数据。
UIImagePickerController 只能通过 UIImagePickerControllerReferenceURL 检索元数据(包括 GPS)。 UIImagePickerControllerReferenceURL 您必须传递 AssetsLibrary 方法,这需要再次启用位置服务。
干杯,

亨德里克

the explanation is quite simple. Instagram uses the UIImagePickerController. UIImagePickerController works without Location Services enabled, but you don't get EXIF data using this method.
UIImagePickerController can retrieve metadata (incl. GPS) only through the UIImagePickerControllerReferenceURL. UIImagePickerControllerReferenceURL you have to pass then AssetsLibrary methods, which needs again location services enabled.
Cheers,

Hendrik

睫毛溺水了 2025-01-03 02:57:21

正如 holtmann 提到的,读取 UIImagePickerControllerReferenceURL 会触发位置服务提示。如果您只需要图像数据,而不需要元数据,则可以从 UIImagePickerControllerOriginalImage 和 UIImagePickerControllerEditedImage 键获取(我首先检查 EditedImage,然后如果 EditedImage 为 null,则检查 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];
    }
}

As holtmann mentioned, reading the UIImagePickerControllerReferenceURL triggers the location services prompt. 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). 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];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文