I am trying to confirm not by typing the button but by replying verbally on an alert window. I have already installed alertController and speechRecognition but I don't know how to make them interact together. This is my code :
presentAlertConfirm() {
this.alertController
.create({
header: 'object detection,
message: 'Are you sure you want to confirm?',
buttons: [
{
text: 'NO',
role: 'cancel',
cssClass: 'secondary',
handler: (data) => {
this.statusConfirm = 'confirmation canceled';
},
},
{
text: 'SI',
handler: () => {
this.statusConfirm = 'confirm OK';
this.viewObjectDetail;
},
},
],
})
.then((confirmElement) => {
confirmElement.present();
});
}
Related
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?
In my ionic app, I need to open a specific page after receiving a push notification.
I'm testing it in the Android Studio emulator and have displayed a bunch of console logs that prove that the push.on('notification').subscribe event is definitely triggering the page using navCtrl.push (I've tried navCtrl.setRoot too) and the ngOnInit is doing everything as normal and making it to the end of its code.
The problem is that after that, the page just isn't showing.
I can see the following message in the Android console log, but I don't really know what it means:
D/SystemWebChromeClient: ng:///AppModule/ShiftDetailsPage.ngfactory.js: Line 563 : ERROR
I/chromium: [INFO:CONSOLE(563)] "ERROR", source: ng:///AppModule/ShiftDetailsPage.ngfactory.js (563)
but they appear before all the console log messages output by ngOnInit in ShiftDetailsPage, so I guess they don't mean there was a problem loading the page.
Another thing that is appearing is:
Cannot read property 'controls' of undefined.
in the app.
I've searched everywhere for someone having a similar problem, but all I can find are descriptions of how to receive notifications, but nothing helpful about how to trigger pages from the event.
Should I use something other than navCtrl.push or is that the correct way?
Any suggestions are very welcome.
Here's the code in the push.on subscribe:
push.on('notification').subscribe(async (data: EventResponse) => {
console.log("in notification, data = " + JSON.stringify(data));
if (data.additionalData.shiftId != null
&& data.additionalData.shiftId != ""
&& await this.login.isLoggedIn()
) {
console.log("in notification, shiftId = " + data.additionalData.shiftId);
console.log("in notification, isLoggedIn = " + JSON.stringify(await this.login.isLoggedIn()));
const confirmAlert = this.alertCtrl.create({
title: 'Shift Notification',
message: data.additionalData.shiftId,
buttons: [
{
text: 'Ignore',
role: 'cancel'
},
{
text: 'View',
handler: () => {
console.log("in notification, handler");
this.shiftDetailsProvider.getShiftDetails(data.additionalData.shiftId).then( async shift => {
const userLocation = await this.getUserLocation().then(userLocation => {
console.log("in pushSetup on notification, userLocation = ", userLocation);
return userLocation;
});
this.navCtrl.push(ShiftDetailsPage, {shift: shift, userLocation: userLocation, sourcePage: "notification"});
});
}
},
]
});
confirmAlert.present();
} else {
console.log("in notification, else");
if (data.additionalData.foreground) {
console.log("in notification, foreground");
const confirmAlert = this.alertCtrl.create({
title: 'New Notification',
message: data.message,
buttons: [
{
text: 'Cancel',
role: 'cancel'
},
{
text: 'OK',
handler: () => {
console.log('New notification callback')
}
},
]
});
confirmAlert.present();
if (this.platform.is('ios')) {
console.log("in notification, platform is ios");
push.finish(data.additionalData.notId);
}
} else {
console.log('Push notification clicked from the background');
}
}
});
The payload I am sending is fine, searched for this a lot, Android foreground notifications are working fine. And in iOS, when the app is in the background or app is closed, I receive notification correctly.
But when the app is in the foreground, I don't get the notification, neither the .on('notification', ()=>{}) is triggered. Any ideas would be helpful.
Already gone through a lot of stuff.
const options: PushOptions = {
android: {},
ios: {
"sound": "true",
"alert": "true",
"badge": "true",
"clearBadge": "true"
},
windows: {},
browser: {
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification')
.subscribe((notification: any) => {
// {
// additionalData: {
// typeData: {}//Sent from server,
// coldstart: "false",
// foreground: "false"
// }
// }
let alertme = this.alert.create({
title : "GOT NOTIFIED",
subTitle : JSON.stringify( notification ),
buttons : [{
text: 'Ok',
handler: () => {
}
}]
});
alertme.present();
});
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();
}
};
}
My View (MyFormPanel)
var controllers = Ext.define("MyApp.controller.formcontroller", {
extend: "Ext.app.Controller",
config: {
refs: {
username: "username"
},
},
launch: function () {
alert('Controller launched');
},
init: function () {
alert('Controller init');
},
myaction : function (options) {
alert('options');
var username = options.username;
this.render ({
xtype: 'MyATM',
username: username})}
});
var formPanel = Ext.create('Ext.form.Panel', {
fullscreen: true,
scrollable: 'vertical',
layout: {
align: 'center',
type: 'vbox'
},
items: [
{
xtype: 'toolbar',
docked: 'top',
title: 'Login Form'
},
{
xtype: 'fieldset',
items: [
{
xtype: 'fieldset',
title:'Enter user name & password',
defaults: {
required: true,
labelAlign: 'left',
labelWidth: '50%'
},
items: [
{
xtype: 'textfield',
name : 'username',
label: 'User Name',
allowBlank:false,
useClearIcon: true
}, {
xtype: 'passwordfield',
name : 'password',
label: 'Password',
allowBlank:false,
useClearIcon: false
},
{
xtype: 'checkboxfield',
required:false,
id: 'RememberMe',
name: 'RememberMe',
label: 'Remember Me',
labelWidth: '50%'
},
{
xtype: 'button',
ui: 'confirm-round',
text: 'Log In' ,
handler: function() {
//Ext.Msg.alert('Form Values', JSON.stringify(formPanel.getValues(), null, 2));
Ext.ControllerManager.get('formcontroller').ControllerMethod({myaction: myaction});
}
}
]
}],
}]
});
formPanel.add({
xtype: 'toolbar',
docked: 'bottom',
layout: { pack: 'center' },
});
My controller (FormController)
Ext.define("MyApp.controller.formcontroller", {
extend: "Ext.app.Controller",
config: {
refs: {
username: "username"
},
},
launch: function () {
alert('Controller launched');
},
init: function () {
alert('Controller init');
},
myaction : function (options) {
alert('options');
var username = options.username;
this.render ({
xtype: 'MyATM',
username: username})}
});
I am using Sencha touch2 with Phonegap 1.4 on android 2.3. When i try to move view to controller on Login button click on handler function to invoke controller , i am getting error , Ext.dispatch is not defined as function .
Tell me the actual way how to move view to controller and vice versa.
Thanks
Ext.dispatch is not the recommended way to use in Sencha Touch 2. It might be removed...
Anyway, the best way to listen to & handle events on your views from controllers is:
Ext.define("MyApp.controller.formcontroller", {
extend: "Ext.app.Controller",
config: {
refs: {
loginButton: "#login-button" // set an id for your login button and this ref works
},
control: {
loginButton: {
tap: 'handleLogin',
}
handle_login: function(){whatever you want to do here}
}
And in Architect...
a. you go to the button's config, and
b. search for Event Handlers, and
c. you press the [+] button on the right.
d. Add a "basic handler"
e. Choose the TAP event
f. Give it a name (onButtonSendTap or whatever)
g. press DONE
h. right mouse
i. Convert to action
j. Choose [New Controller] or an existing controller
k. If you chose new controller give it a name
and voilla, you have your handler in the controller.
And in Architect...
a. you go to the button's config, and
b. search for Event Bindings, and
c. you press the [+] button on the right.
d. Add a "basic handler"
e. Choose the TAP event
f. Give it a name (onButtonSendTap or whatever)
g. press DONE
h. right mouse
i. Convert to action
j. Choose [New Controller] or an existing controller
k. If you chose new controller give it a name
and voilla, you have your handler in the controller.