我有一个使用位置权限的 React Native Expo 应用程序。它在我的设备和模拟器上运行良好,因此进入分发的下一步 - TestFlight。当我将 ipa 加载到 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); …Run Code Online (Sandbox Code Playgroud) 我试图在渲染后动态查找组件的位置。我尝试使用 useRef 和 getBoundingClientRect() (参见下面的代码)。
我得到的回应是这样的。
myRef.current.getBoundingClientRect 不是函数。(在“myRef.current.getBoundingClientRect()”中,“myRef.current.getBoundingClientRect”未定义)。
有什么想法我做错了吗?
import React, { useState, useRef } from "react";
import { View, Button, TextInput } from "react-native";
const MyComponent = () => {
const [value, onChangeText] = useState("Useless Placeholder");
const myRef = useRef();
const showRefPosition = () => {
console.log("button clicked, set focus and log position");
// this works and shows that i am using the ref correctly
myRef.current.focus();
// however, this does not work and throws the eror
let componentPosition = …Run Code Online (Sandbox Code Playgroud)