发布到Testflight时React Native Expo应用崩溃

时间:2019-12-03 12:11:26

标签: ios geolocation expo testflight react-native-maps

我有一个使用“位置”权限的React Native Expo应用程序。它在我的设备和模拟器上都很好用,因此请转到下一步分发-TestFlight。当我将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 个答案:

答案 0 :(得分:2)

已解决:)-如果其他人遇到这种问题(因为我被困住了几天并构建起来),它将离开这里。

我的问题是我要从同时安装了Mapview的组件的useEffect挂钩中请求用户位置。在Mapview中,我将provider道具设置为google

如果执行此操作,则必须在信息plist中添加gogleMapApi键。为了公平起见,Expo实际上确实在MapView文档中声明了这一点,但在Android文档之后,它恰好位于底部。在浏览了数小时的日志并发现问题是Google api错误而不是权限位置错误后,我从该线程中意识到了我的问题和解决方案。

[https://forums.expo.io/t/how-to-set-googlemaps-with-gmsservices-provideapikey/17770][1]

希望这对某人有帮助!

答案 1 :(得分:2)

我还面临无法识别JS错误的问题,我想分享如何调试此错误。

对于iOS,您可以使用模拟器选项构建独立应用,崩溃日志存储在此处:

~/Library/Logs/DiagnosticReports/

我在这里写了更多细节。

https://medium.com/@tak215/expo-rash-on-standalone-app-only-how-to-debug-29c88c69c821?sk=babf382671e1c8c5bf97a74773d4f4f5