真的被困在这里,需要帮助。
PermissionsAndroid始终返回“ never_ask_again”,而react-native-permissions始终返回“ restricted” 下面是代码片段:
async _getLocationAsync(){
if (Platform.OS === 'android') {
Permissions.request('location').then(response => {
// Returns once the user has chosen to 'allow' or to 'not allow' access
// Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
Alert.alert(" ",response);
});
} else if (Platform.OS === 'ios') {
//this.nextAction();
Alert.alert(" ",Platform.OS);
}}
AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permisssion.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permisssion.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.location" />
compileSdkVersion 25
buildToolsVersion“ 23.0.1”
minSdkVersion 16
targetSdkVersion 25
compileSdkVersion 23
buildToolsVersion“ 23.0.1”
下面的代码与PermissionsAndroid一起使用,给了我“ never_ask_again”响应。
async _getLocationAsync(){
if (Platform.OS === 'android') {
var permissions = [
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION
];
try {
PermissionsAndroid.requestMultiple(permissions).then(granted => {
Object.entries(granted).map(([key, value]) => {
Alert.alert(key,value);
});
//Alert.alert(granted);
});
} catch (err) {
Alert.alert(granted);
}
} else if (Platform.OS === 'ios') {
//this.nextAction();
Alert.alert(Platform.OS);
}
}
我已经在2个真实设备和2个仿真器上进行过尝试,并且其输出相同。
我还尝试了targetSDKVersion = 23和buildSDKVersion = 23及其相同的输出。
react-native-cli:2.0.1 反应本机:0.55.4
我在做什么错了?
答案 0 :(得分:0)
找到了答案。好极了! 如果您遇到相同的问题,可以通过以下方法解决该问题:
方案:您正在使用: react-native-facebook-login 反应本地地理位置服务 (我认为如果您使用PermissionsAndroid,也会发生相同的问题。)
两个相互冲突。地理定位有效,但Facebook登录使应用程序崩溃。
以下是对我有用的设置:
build.gradle
compileSdkVersion 25
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.xyz.abc"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
allprojects {
repositories {
jcenter()
maven { url "https://maven.google.com" }
}
}
compile project(':react-native-facebook-login')
compile(project(':react-native-geolocation-service')) {
exclude group: 'com.google.android.gms'
}
compile ("com.google.android.gms:play-services-base:+") {
force = true;
}
compile ("com.google.android.gms:play-services-location:+") {
force = true;
在react-native-facebook-login模块的build.gradle中(位于node_modules文件夹中),将facebook-android-sdk更改为4.19。+,如下所示
compile ('com.facebook.android:facebook-android-sdk:4.19.+')
PS:Havent还在多个Android设备上进行了测试。
此外,此页面对于类似问题也很有帮助: https://github.com/transistorsoft/react-native-background-geolocation/issues/229