how to solve [CoreBluetooth] XPC connection invalid react native? - android

I'm trying to enable the bluetooth when its off using react native by this code
when its turned on the modal asking permission using bluetooth is showed up, but i want to show modal alert again when the bluetooth turned off. So how to show the modal it can be redirect to settings on both android and ios ?
this.setState({ isEnabledSwitch: !this.state.isEnabledSwitch })
const bluetoothPermission = Platform.OS === 'ios' ? PERMISSIONS.IOS.BLUETOOTH_PERIPHERAL : PERMISSIONS.ANDROID.BLUETOOTH_PERIPHERAL;
request(bluetoothPermission).then((result) => {
console.log('result', result);
const title = '“Wynn Resorts” would like to use Bluetooth';
const description = 'Wynn Resorts needs your Bluetooth enabled to use Digital Key features to access your room with your phone. Please go to Settings > Wynn Resorts and turn on Bluetooth in order to allow access.';
Alert.alert(
title,
description,
[
{
text: 'Cancel',
onPress: () => {
this.isDialogShown = false;
// this.gotoWayfinding();
}
},
{
text: 'Settings',
onPress: () => {
this.isDialogShown = false;
if (Platform.OS === 'ios') {
Linking.openURL('app-settings:')
} else {
this.props.navigation.goBack();
NativeModules.OpenSettings.openNetworkSettings(data => {/*This is intentional*/ });
}
}
}
],
{ cancelable: true }
);
}).catch((error) => {/*This is intentional*/ })
}
but when i try in real device the xcode show logs of
2022-03-14 19:19:05.493649+0700 appsTrial[657:117152] [CoreBluetooth] XPC connection invalid
how to solve this problem?

Related

Local Notification with Notifee does not displaying in Android

I am having an issue where the local notification is not displaying in android though it is displaying in IOS. I have created permissions and battery optimization check to see if that is the problem. The notification does make a sound and appear shows a little square in the upper left that if I click and drag does show the local notification. I am using an emulator right now and I have tried it on a real device.
This is the way I am calling the notification.
<Button
title="Trigger Push Notification"
size="large"
onPress={() => onDisplayNotification('default', 'Default Channel', 'Spotback
Android', 'Local push notification')}
/>
This is is the Notifee component.
import notifee, { AndroidStyle, AuthorizationStatus, Notification } from '#notifee/react-native';
import { Alert } from 'react-native';
export const onDisplayNotification = async (id, name, title, body, smallIcon?) => {
// Request permissions (required for iOS)
await notifee.requestPermission();
const settings = await notifee.getNotificationSettings();
const batteryOptimizationEnabled = await notifee.isBatteryOptimizationEnabled();
if (batteryOptimizationEnabled) {
// 2. ask your users to disable the feature
Alert.alert(
'Restrictions Detected',
'To ensure notifications are delivered, please disable battery optimization for the app.',
[
// 3. launch intent to navigate the user to the appropriate screen
{
text: 'OK, open settings',
onPress: async () => await notifee.openBatteryOptimizationSettings(),
},
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel',
},
],
{ cancelable: false }
);
}
if (settings.authorizationStatus == AuthorizationStatus.AUTHORIZED) {
console.log('Notification permissions has been authorized');
} else if (settings.authorizationStatus == AuthorizationStatus.DENIED) {
console.log('Notification permissions has been denied');
}
// }
// Create a channel (required for Android)
const channelId = await notifee.createChannel({
id,
name,
});
await notifee.displayNotification({
title,
body,
android: {
channelId,
smallIcon,
pressAction: {
id,
},
},
});
};
Please change your channel id (default) and channel name (Default Channel) to something else like:
id: custom_channel
name: custom_channel

iOS camera permissions, native iOS permission alert not firing on first request

Hi all I have an app with a feature that allows the user to take a picture during a task.
Recently when asking for camera permissions for the first time the device is not showing the native alert but rather deferring to my secondary alert that is supposed to be used if the user had denied or changed their permissions settings after the first attempt.
My understanding is that when a device is asked for the first time iOS will supply the permissions alert similar to this
I have this in my info.plist
<key>NSCameraUsageDescription</key>
<string>Allow access to your camera to take pictures of your dog!</string>
code when the user taps the camera button in app (solution at bottom)
function takePhoto() {
check(
Platform.select({
ios: PERMISSIONS.IOS.CAMERA,
android: PERMISSIONS.ANDROID.CAMERA,
})
)
.then(async (response) => {
if (response == 'unavailable') {
alert('Camera is not available on this device');
return;
}
const userId = auth().currentUser.uid;
let image = null;
const mapAPI = new MapAPI(firestore(), userId, storage);
const showSettingsAlert = (title, message) => {
Alert.alert(
title,
message,
[
{
text: translations['settings.goto'],
onPress: async () => {
Linking.openSettings();
},
},
{
text: translations['cancel'],
onPress: () => {
console.log('Cancel Pressed');
},
style: 'cancel',
},
],
{ cancelable: true }
);
};
if (response != RESULTS.GRANTED) {
showSettingsAlert(
translations['permissions.cameratitle'],
translations['permissions.cameradesc']
);
return;
}
I've been trying to tackle this for a while and appreciate any help. Thanks!
You are testing for response != RESULTS.GRANTED. So, if it is “not determined” (the status prior to asking the user’s permissions), that would result in your alert. We generally show our custom alert if the status is “denied” or “restricted”, rather than not “granted”.
I realized with the help from another overflower that I had not requested to access the camera before calling the custom alert.
Here is the solution that worked in my instance.
const takePhoto = async () => {
const imageProps = {
mediaType: 'photo',
width: 400,
height: 400,
writeTempFile: true,
};
const userId = auth().currentUser.uid;
let image = null;
const mapAPI = new MapAPI(firestore(), userId, storage);
try {
image = await ImageCropPicker.openCamera(imageProps);
} catch (error) {
console.log(error);
const response = await check(
Platform.select({
ios: PERMISSIONS.IOS.CAMERA,
android: PERMISSIONS.ANDROID.CAMERA,
})
);
if (response !== RESULTS.GRANTED && response !== RESULTS.UNAVAILABLE) {
showSettingsAlert(
translations['permissions.cameratitle'],
translations['permissions.cameradesc']
);
}
}
if (!image) {
return;
}

Using react-native-wifi-reborn to do auto connect to wifi on android and ios with react-native

I am making an app to control the device, I use react-native-wifi-reborn to connect to a hidden wifi, but when I call the connect function, the phone asks for permission to change wifi and I click allow, but after that, the permission request is repeated until the wifi connects wifi, the requesting permission stops.
How can I fix this error. Looking forward to everyone's help !. Thank you!
My english is not good, looking forward to your help!
i'm using:
react-native: 0.60.5,
react-native-wifi-reborn: 4.3.4,
Here is the picture asking for permission and the code you use to connect.
onPressChangeWifi = async() => {
const checkpermission = await PermissionsAndroid.check(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
)
if(!checkpermission){
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
title: 'Location permission is required for WiFi connections',
message:
'This app needs location permission as this is required ' +
'to scan for wifi networks.',
buttonNegative: 'DENY',
buttonPositive: 'ALLOW',
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
// You can now use react-native-wifi-reborn
connectToWifi()
} else {
// Permission denied
}
}else{
connectToWifi()
}
}
const connectToWifi = () => {
WifiManager.connectToProtectedSSID('MarsWiFi4282', '123567890' , false).then(
() => {
console.warn("Connected successfully!");
},
() => {
console.warn("Connection failed!");
}
);
WifiManager.getCurrentWifiSSID().then(
ssid => {
console.warn("Your current connected wifi SSID is " + ssid);
},
() => {
console.warn("Cannot get current SSID!");
}
);
}

App notification setting access in EXPO sdk39

Problem started when i realize that Permissions.askAsync not working as expected.
I find Permissions.askAsync not working as expected and it`s cool solution for ios, but i need it for android! So, i add some extra code for this:
Alert.alert(
'No Notification Permission',
'please go to settings and enable notifications permissions manually',
[
{ text: 'cancel', onPress: () => console.log('cancel') },
{
text: 'Allow',
onPress: async () => {
if (Platform.OS === 'android') {
await IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_APP_NOTIFICATION_SETTINGS,
{
data: `package:${Application.applicationId}`,
}
);
}
if (Platform.OS === 'ios') {
Linking.openURL('app-settings:');
}
},
},
],
{ cancelable: false },
);
UPD. construction below works great, but i want to access directly to the APP_NOTIFICATION_SETTINGS.
onPress={() => {
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
{
data: `package:${Application.applicationId}`,
}
);
}}
Related issue in expo forums https://forums.expo.io/t/opening-device-settings-on-android-using-linking/2059/14
I try to access to the APP_NOTIFICATION_SETTINGS but for some reason i'm getting error like "The app wasn't found in the list of installed apps". Tried it on published project and on standalone (apk) and got the same result. Anyone knows what is the problem?
I realize this is a bit late, but the suggested answer didn't work for me. This is what worked on my device using Android Version 29:
const pkg = Constants.manifest.releaseChannel
? Constants.manifest.android.package
: 'host.exp.exponent';
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_APP_NOTIFICATION_SETTINGS,
{
extra: { 'android.provider.extra.APP_PACKAGE': pkg }
},
);
TL;DR: The key change here being android.provider.extra.APP_PACKAGE as the extra key name.
Solution:
const pkg = Constants.manifest.releaseChannel
? Constants.manifest.android.package // When published, considered as using standalone build
: 'host.exp.exponent'; // In expo client mode
onPress: () => {
if (Platform.OS === 'android') {
if (Platform.Version >= 26) {
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_APP_NOTIFICATION_SETTINGS,
{
data: `package:${pkg}`,
},
);
} else {
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_APPLICATION_DETAILS_SETTINGS,
{
data: `package:${pkg}`,
},
);
}
}
if (Platform.OS === 'ios') {
Linking.openURL('app-settings:');
}
},
Solution description: https://forums.expo.io/t/api-to-open-app-settings/5290/18

React native geolocation getCurrentPosition no reponse (android)

I have read and tested a lot of issues but I still can not get geolocation on Android.
I use navigator.geolocation.getCurrentPosition, on iOS everything works fine, but on Android I have no answer to this function, either success or error.
I have installed react-native-permissions to make sure that the user has activated the permissions but it does not change anything because it says that everything is "authorized".
I noticed that it came from GPS of the device. If I activate it manually, everyting works fine. However, I can not find a way to activate it for the user. On iOS, if GPS is not activated, I fall in the error callback and tell user to activate it, but on android, nothing is happennig.
I don't understand why I can't get geolocation only with getCurrentPosition (I have ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION in manifest).
Here a part of my code:
componentDidMount() {
navigator.geolocation.getCurrentPosition(
(position) => {
//do my stuff with position value
},
(error) => {
Permissions.getPermissionStatus('location')
.then((response) => {
if (response !== "authorized") {
Alert.alert(
"Error",
"We need to access to your location",
[
{
text: "Cancel",
onPress: () => {
// do my stuff
}, style: 'cancel'
},
{
text: "Open Settings",
onPress: () => Permissions.openSettings()
}
]
);
} else {
// do my stuff
}
});
},
{ enableHighAccuracy: true, timeout: 2000, maximumAge: 1000 }
);
}
Does anyone have any idea ?
Thank you
You should need to enable GPS on android
For enabling location/gps on Android I can recommend this module:
https://github.com/Richou/react-native-android-location-enabler
It is using the standard Android dialog for location:
like this
import React, { Component } from "react";
import { Text, StyleSheet, View, Platform } from "react-native";
import RNAndroidLocationEnabler from "react-native-android-location-enabler";
export default class index extends Component {
componentDidMount() {
this.getLocation();
}
onLocationEnablePressed = () => {
if (Platform.OS === "android") {
RNAndroidLocationEnabler.promptForEnableLocationIfNeeded({
interval: 10000,
fastInterval: 5000,
})
.then((data) => {
this.getLocation();
})
.catch((err) => {
alert("Error " + err.message + ", Code : " + err.code);
});
}
};
getLocation = () => {
try {
navigator.geolocation.getCurrentPosition(
(position) => {
//do my stuff with position value
},
(error) => {
Permissions.getPermissionStatus("location").then((response) => {
if (response !== "authorized") {
Alert.alert("Error", "We need to access to your location", [
{
text: "Cancel",
onPress: () => {
// do my stuff
},
style: "cancel",
},
{
text: "Open Settings",
onPress: () => Permissions.openSettings(),
},
]);
} else {
// do my stuff
}
});
},
{ enableHighAccuracy: true, timeout: 2000, maximumAge: 1000 }
);
} catch (error) {
this.onLocationEnablePressed();
}
};
}

Categories

Resources