Skip to content

[iOS] Geolocation API not work on RN 0.50.3 #16928

@jacobchen

Description

@jacobchen

Is this a bug report?

Yes

Environment

OS:  macOS Sierra 10.13.1
Node:  8.9.1
Yarn:  0.21.3
npm:  5.5.1
Xcode:  Xcode 9.1 Build version 9B55

react-native: 0.50.3
react: 16.0.0
Test device: Simulator iPhone6s / iOS11

Steps to Reproduce

  1. create a pure app with command: react-init geoTest

  2. Setup the app as following: include NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription in the info.plist, add location as a background mode in the 'Capabilities' tab in Xcode

  3. Add code as below:

componentDidMount() {
     navigator.geolocation.getCurrentPosition(
          (position) => {
            console.log("position.coords: ", position.coords);
          },
          (error) => this.setState({ error: error.message }),
          { enableHighAccuracy: true, useSignificantChanges: true, distanceFilter:10, timeout: 20000, maximumAge: 1000 },
        );
}

Below error message show up:

TypeError: Cannot read property 'geolocation' of undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    StaleThere has been a lack of activity on this issue and it may be closed soon.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions