React-Native地理位置可在Android设备上使用,但不适用于iPhone

时间:2019-09-25 19:30:43

标签: ios react-native geolocation

在Android上使用react-native的geolocation模块工作正常,但在iPhone设备上,该模块的任何功能的错误消息均不起作用

我尝试在页面组件上使用直接方法作为使其异步的函数,但它不起作用,使用通过传奇中间件的操作也不起作用。 我尝试了所有模块方法,但都没有答案

组件位置(页面)

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>
  );
}

动作位置

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

Sagas位置

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"
}

信息系统

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>

不是错误,不是回报。 在反应堆中 https://ibb.co/0M54GMC

1 个答案:

答案 0 :(得分:0)

我解决了在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>

但是导航模块不能很好地工作,它占据了一个位置,但是如果我再按一次,它就不会再次缩回该位置。 谢谢大家。