Skip to content

IOS requestAuthorization doesn't return success or error until you go into the settings and switch the permission value #335

@crasyboy42

Description

@crasyboy42

Environment

My machine (windows, build on a mac mini):

System:
  OS: Windows 10 10.0.19045
  CPU: (4) x64 Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz
  Memory: 4.25 GB / 15.94 GB
Binaries:
  Node:
    version: 18.14.2
    path: C:\Program Files\nodejs_v18\node.EXE
  Yarn:
    version: 1.22.10
    path: ~\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 9.5.0
    path: C:\Program Files\nodejs_v18\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK: Not Found
IDEs:
  Android Studio: Not Found
  Visual Studio:
    - 17.10.35122.118 (Visual Studio Community 2022)
    - 16.11.33529.622 (Visual Studio Community 2019)
Languages:
  Java:
    version: 17.0.12
    path: /c/Program Files/Microsoft/jdk-17.0.12.7-hotspot/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.75.3
    wanted: 0.75.3
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

The remote server:

System:
    OS: Linux 5.4 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (2) x64 Intel(R) Xeon(R) CPU E5-2687W v4 @ 3.00GHz
    Memory: 1.83 GB / 3.83 GB
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.20.4 - ~/.nvm/versions/node/v18.20.4/bin/node
    Yarn: Not Found
    npm: 10.7.0 - ~/.nvm/versions/node/v18.20.4/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: Not Found
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.3.1 => 18.3.1
    react-native: 0.75.3 => 0.75.3
  npmGlobalPackages:
    *react-native*: Not Found

Platforms

iOS

Versions

  • Android: -
  • iOS: 17.6.1
  • react-native-geolocation: 3.4.0
  • react-native: 0.75.3
  • react: 13.3.1

Description

On iOS the .requestAuthorization seems to do nothing until you go into the settings and switch the location permission then suddenly all pending requests are returned in success/error.
Android required me to set locationProvider to playServices but no matter what I try for the iOS configurations I can't get it to call a function normally.

Reproducible Demo

This is the exact code i use in our project and in a clean project. (with moment.js installed for timing)

Info.plist has this key NSLocationWhenInUseUsageDescription but no value

// this seems to work fine on android
Geolocation.setRNConfiguration({
    locationProvider:   'playServices',
    authorizationLevel: 'whenInUse'
});

let moment_object = moment();

// this gets called
console.log('Geolocation.requestAuthorization', Geolocation.requestAuthorization, moment_object.format('HH:mm:ss'));

// success or error only gets called when you go into the iOS settings and switch the location permissions
// otherwise this just hangs in limbo
Geolocation.requestAuthorization(() => { // success callback
    console.log('Geolocation.requestAuthorization', true, moment_object.format('HH:mm:ss'), moment().format('HH:mm:ss'));
}, () => { // error callback
    console.log('Geolocation.requestAuthorization', false, moment_object.format('HH:mm:ss'), moment().format('HH:mm:ss'));
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions