Search code examples
iosreact-nativegeolocation

React-Native geolocation works on Android device but not on iPhone


Using react-native's geolocation module on android works fine but on iphone device it doesn't work either error message of any of the module's functions

I tried using the direct method on the page component as a function that makes it asynchronous but it didn't work, using the action that goes through the saga middleware doesn't work either. I tried all the module methods and none of them I have an answer

Componente Position(Page)

import React, {useState, useEffect} from 'react';
import {useDispatch, useSelector} from 'react-redux';

import {Container, Image} from './styles';

import * as PositionActions from '../../store/modules/position/action';

import Header from '../../components/Header';
import Button from '../../components/Button';
import ButtonGroup from '../../components/ButtonGroup';
import Fundo from '../../../assets/images/FundoPosicionamento.png';

export default function Position() {

  const dispatch = useDispatch();

  function handlePositionDot(dot) {
    dispatch(PositionActions.PositionRequest(dot));
  }

  return (
    <Container>
      <Image source={Fundo} resizeMode="stretch">
        <Header buttonExist={false} />
        <ButtonGroup

          functionOnPressA={() => handlePositionDot(true)}
        />
      </Image>
    </Container>
  );
}

Actions position

export function PositionRequest(dot) {
  return {
    type: '@position/REQUEST_POSITION',
    payload: {
      dot,
    },
  };
}

Sagas position

import Geolocation from '@react-native-community/geolocation';

function getCurrentPosition() {
  return new Promise((resolve, reject) => {
    Geolocation.getCurrentPosition(resolve, reject, {
      enableHighAccuracy: true,
      timeout: 15000,
      maximumAge: 500,
    });
  });
}

function* requestPosition(action) {
  yield put(
    PositionLoadingActivityOnDot('gravando informações...', action.payload.dot)
  );
  try {
    const position = yield call(getCurrentPosition);
    console.tron.log(position)
    const {accuracy, altitude, longitude, latitude} = position.coords;
    yield put(
      PositionRequestSuccess(
        'coletada localização com sucesso',
        action.payload.dot,
        accuracy,
        altitude,
        longitude,
        latitude
      )
    );
  } catch (err) {
    yield put(
      PositionRequestFailure(
        '005-erro de localização verifique seu smartphone',
        action.payload.dot
      )
    );
  }
}

pakcage.json

  "dependencies": {
    "@react-native-community/async-storage": "^1.6.1",
    "@react-native-community/geolocation": "^2.0.2",
    "axios": "^0.19.0",
    "immer": "^4.0.0",
    "prop-types": "^15.7.2",
    "react": "16.8.6",
    "react-native": "0.60.5",
    "react-native-gesture-handler": "^1.4.1",
    "react-native-masked-text": "^1.13.0",
    "react-native-reanimated": "^1.2.0",
    "react-native-vector-icons": "^6.6.0",
    "react-navigation": "^4.0.3",
    "react-navigation-stack": "^1.5.5",
    "react-redux": "^7.1.1",
    "reactotron-react-native": "^3.6.5",
    "reactotron-redux": "^3.1.1",
    "reactotron-redux-saga": "^4.2.2",
    "redux": "^4.0.4",
    "redux-saga": "^1.0.5",
    "styled-components": "^4.3.2"
}

info system

System:
    OS: macOS High Sierra 10.13.6
    CPU: (8) x64 Intel(R) Core(TM) i7-2675QM CPU @ 2.20GHz
    Memory: 33.22 MB / 4.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.16.0 - /usr/local/bin/node
    Yarn: 1.17.3 - /usr/local/bin/yarn
    npm: 6.9.0 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
    Android SDK:
      API Levels: 26, 27, 28, 29
      Build Tools: 27.0.3, 28.0.3, 29.0.0
      System Images: android-28 | Google APIs Intel x86 Atom, android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.2 AI-181.5540.7.32.5056338
    Xcode: 10.1/10B61 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.8.6 => 16.8.6
    react-native: 0.60.5 => 0.60.5
  npmGlobalPackages:
    react-native-cli: 2.0.1

info.pslist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>Betta Hidroturbinas</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>NSLocationAlwaysAndWhenInUseUsageDescription</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string></string>
    <key>UIAppFonts</key>
    <array>
        <string>Roboto-Black.ttf</string>
        <string>Roboto-BlackItalic.ttf</string>
        <string>Roboto-Bold.ttf</string>
        <string>Roboto-BoldItalic.ttf</string>
        <string>Roboto-Light.ttf</string>
        <string>Roboto-LightItalic.ttf</string>
        <string>Roboto-Medium.ttf</string>
        <string>Roboto-MediumItalic.ttf</string>
        <string>Roboto-Regular.ttf</string>
        <string>Roboto-RegularItalic.ttf</string>
        <string>Roboto-Thin.ttf</string>
        <string>Roboto-ThinItalic.ttf</string>
    </array>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
</dict>
</plist>

Not a mensage the error,not a return. in reactotron https://ibb.co/0M54GMC


Solution

  • I resolved the problem add tree lines in Info.plist

    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Autorize para recolhermos sua localização.</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Autorize para recolhermos sua localização.</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Autorize para recolhermos sua localização.</string>
    

    but the navigation module doesn't work very well, it takes a position, but if I press again it does not retract the position again. thank you all.