How to remove location services request from Phone

2019-06-08 19:58发布

问题:

I am using PhoneGap 2.8 to create an iOS 6 app. I am building it in XCode, not using PhoneGap Build. My app does not require location services, but uses the camera. Every time it returns from the camera.getPicture() call, it shows a dialog to allow my app to use location services. If I say no, or location services are disabled, the photo does not get passed back to my app.

This happens even if I deny the camera app location services in the privacy settings. I have also edited my config.xml and removed all references to CDVLocation. There are no references to navigator.geolocation in my javascript code.

Why is it asking for location services? Is there somewhere else in my XCode project I need to remove this permission, or exclude a phonegap module? Does iOS 6 display this prompt to any app that uses the camera, even if the user has already blocked the camera from using location services?

Thanks for any assistance.

回答1:

It seems that Phonegap automatically add EXIF data to Jpeg image taken with the camera which in turns triggers the location services alert. There are two ways to prevent that from happening:

1 - Specify PNG for the format of the captured picture (by default phonegap uses JPEG which contains EXIF data)

encodingType=navigator.camera.EncodingType;

function capturePhotoEdit() {
        navigator.camera.getPicture(onPhotoDataSuccess, onFail, { encodingType: encodingType.PNG, destinationType: destinationType.DATA_URL });
    }

2 - If you want to use JPEG instead of PNG images, you will have to comment out these lines in CordovaLib/Classes/CDVCamera.m between lines 312 and 322. This is the code that adds the EXIF data to the picture.

        NSDictionary *controllerMetadata = [info objectForKey:@"UIImagePickerControllerMediaMetadata"];
        if (controllerMetadata) {
            self.data = data;
            self.metadata = [[NSMutableDictionary alloc] init];

            NSMutableDictionary *EXIFDictionary = [[controllerMetadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy];
            if (EXIFDictionary) [self.metadata setObject:EXIFDictionary forKey:(NSString *)kCGImagePropertyExifDictionary];

            [[self locationManager] startUpdatingLocation];
            return;
        }