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

1.2k Views Asked by At

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.

2

There are 2 best solutions below

0
On

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

0
On

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