Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-13680

cordova-plugin-geolocation permission request going wrong in newer iOS version

Agile BoardAttach filesAttach ScreenshotAdd voteVotersStop watchingWatchersLinkUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • Master
    • None
    • iOS

    Description

      When you want to request the always access location permissions the newer iOS version requires that the NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription are both set. It is not allowed to only set the NSLocationAlwaysUsageDescription anymore.

      But in the Cordova code there is a check that when you have the NSLocationWhenInUseUsageDescription set, the application will only ask the user permission to use the location in app usage (requestWhenInUseAuthorization). It will run the requestAlwaysAuthorization.

      I saw a different issue reported 2 years ago with the question reversed (CB-8826). This was then implemented, but is not working with the latest version. The following code should be edited:

      
      #ifdef __IPHONE_8_0
          NSUInteger code = [CLLocationManager authorizationStatus];
          if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) { //iOS8+
              __highAccuracyEnabled = enableHighAccuracy;
              if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]){
                  [self.locationManager requestWhenInUseAuthorization];
              } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
                  [self.locationManager  requestAlwaysAuthorization];
              } else {
                  NSLog(@"[Warning] No NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key is defined in the Info.plist file.");
              }
              return;
          }
      #endif
      
      

      It should be:

      
      #ifdef __IPHONE_8_0
          NSUInteger code = [CLLocationManager authorizationStatus];
          if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)] || [self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])) { //iOS8+
              __highAccuracyEnabled = enableHighAccuracy;
              if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationAlwaysUsageDescription"]) {
                  [self.locationManager  requestAlwaysAuthorization];
              } else if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]){
                  [self.locationManager requestWhenInUseAuthorization];
              } else {
                  NSLog(@"[Warning] No NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key is defined in the Info.plist file.");
              }
              return;
          }
      #endif
      
      

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            babettestam Babette Stam

            Dates

              Created:
              Updated:

              Slack

                Issue deployment