React Native Expo应用程序在发布到TestFlight后崩溃

7
我有一个使用位置权限的React Native Expo应用程序,在我的设备和模拟器上都非常好用,现在进入下一步——分发测试。当我将ipa加载到TestFlight并尝试运行应用程序时,应用程序在请求用户权限时工作正常(因此应用程序已加载,身份验证工作正常,链接到我的服务器和数据库等都正常)。
当代码请求用户位置权限时,通常的警告“只在使用应用程序时允许、始终允许、不允许”会在屏幕上闪烁几毫秒,然后应用程序崩溃,我获得了将评论分享给Testflight的选项。
请求许可的代码如下:
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';
import createDataContext from '../../Context/createDataContext';

const deviceLocationReducer = (state, action) => {
  switch (action.type) {
    case 'get_device_location':
      return action.payload;
    default:
      return state;
  }
};

const getDeviceLocation = dispatch => async () => {
  let deviceLocation = null;
  try {
    // Ask User permission for location
    const { status } = await Permissions.askAsync(Permissions.LOCATION);
    console.log('\n***\nDeviceLocationContext.js: Permission status', status);
    if (status === 'granted') {
      // Permission granted, get user location
      deviceLocation = await Location.getCurrentPositionAsync({});
      console.log('DeviceLocationContext.js: Setting Context', deviceLocation);
    } else {
      console.log(
        'DeviceLocationContext.js: Permission to access location denied'
      );
    }

    dispatch({
      type: 'get_device_location',
      payload: deviceLocation,
    });
  } catch ({ message }) {
    console.log(
      `DeviceLocationContext.js: Get Device Location Error: ${message}`
    );
  }
};

export const { Context, Provider } = createDataContext(
  deviceLocationReducer,
  { getDeviceLocation },
  null
);

这里是app.json

{
  "expo": {
    "name": "MyApp",
    "description": "MyApp Description",
    "slug": "client",
    "privacy": "public",
    "sdkVersion": "35.0.0",
    "platforms": ["ios", "android"],
    "version": "0.0.7",
    "orientation": "portrait",
    "icon": "./assets/images/icon.png",
    "splash": {
      "image": "./assets/images/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "supportsTablet": true,
      "bundleIdentifier": "com.reachout.myapp",
      "icon": "./assets/images/icon.png",
      "infoPlist": {
        "NSCameraUsageDescription": "Please allow access to add your photo.",
        "NSPhotoLibraryUsageDescription": "Please allow access to select an image from your photo library.",
        "NSLocationWhenInUseUsageDescription": "Please allow access to show venues near you"
      },
      "buildNumber": "0.0.7"
    },
    "android": {
      "permissions": [
        "CAMERA",
        "ACCESS_COARSE_LOCATION",
        "ACCESS_FINE_LOCATION"
      ],
      "versionCode": 7,
      "icon": "./assets/images/icon.png"
    }
  }
}

这里是 package.json。

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "@expo/vector-icons": "^10.0.6",
    "axios": "^0.19.0",
    "expo": "^35.0.0",
    "expo-camera": "^7.0.0",
    "expo-constants": "~7.0.0",
    "expo-font": "^7.0.0",
    "expo-image-picker": "~7.0.0",
    "expo-location": "~7.0.0",
    "expo-permissions": "^7.0.0",
    "lodash": "^4.17.15",
    "react": "16.8.3",
    "react-dom": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
    "react-native-elements": "^1.2.7",
    "react-native-gesture-handler": "^1.3.0",
    "react-native-image-picker": "^1.1.0",
    "react-native-map-clustering": "^3.0.6",
    "react-native-maps": "^0.26.1",
    "react-native-paper": "^3.1.1",
    "react-native-ratings": "^6.5.0",
    "react-native-reanimated": "^1.2.0",
    "react-native-web": "^0.11.7",
    "react-navigation": "^4.0.10",
    "react-navigation-stack": "^1.9.4",
    "react-navigation-tabs": "^2.5.6"
  },
  "devDependencies": {
    "babel-eslint": "^9.0.0",
    "babel-preset-expo": "^7.0.0",
    "eslint": "^5.16.0",
    "eslint-config-airbnb": "^17.1.1",
    "eslint-config-prettier": "^4.3.0",
    "eslint-config-wesbos": "0.0.19",
    "eslint-plugin-html": "^5.0.5",
    "eslint-plugin-import": "^2.18.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.1",
    "eslint-plugin-react": "^7.16.0",
    "eslint-plugin-react-hooks": "^1.7.0",
    "prettier": "^1.19.1"
  },
  "private": true
}

有没有什么想法?我完全一片空白——我已经在生产和开发环境下运行了来自Expo的构建,清除了Expo缓存,并删除了应用程序并重新加载,但都无济于事。
所以,我有一个“可工作”的应用程序,但无法分发进行测试。救命啊!!
另外,我不知道如何调试或访问Testflight上expo构建应用程序的崩溃数据——任何帮助将不胜感激。谢谢。
2个回答

9
解决了 :) - 我会留在这里,以防其他人遇到类似的问题,因为这个问题让我卡了好几天和构建。
我的问题是我在一个组件中从useEffect hook请求用户位置,并挂载了Mapview。在Mapview中,我将我的provider属性设置为google
如果你这样做,那么你必须在你的info plist中添加一个gogleMapApi密钥。公平地说,Expo实际上在MapView文档中声明了这一点,但它在Android文档之后的小节中。在翻阅我的日志数小时后,我意识到我的问题和解决方案来自于这个线程,发现问题不是权限位置而是谷歌API错误。
[https://forums.expo.io/t/how-to-set-googlemaps-with-gmsservices-provideapikey/17770][1] 希望这能帮助到某个人!

这对我来说也非常接近所发生的情况--在我的情况下,我甚至没有要求用户的权限,只是调用了Expo MapView而没有使用Google地图API密钥...在Expo Go、Testflight上工作得很好:不行。谢谢! - agrippa

6

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接