I used Geolocation in my react native code to get the current position and it is working well on Android. But not work on iOS.
Here is my code
import Geolocation from "#react-native-community/geolocation";
import Geocoder from "react-native-geocoder";
_getCurrentLocation = () => {
Alert.alert(
"Get Location",
"Do you want to update your location?",
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
},
{
text: 'UPDATE', onPress: () => {
Geolocation.setRNConfiguration({ skipPermissionRequests: true, authorizationLevel: "always" });
if (Platform.OS === 'ios') Geolocation.requestAuthorization();
Geolocation.getCurrentPosition(
info => {
const position = { lat: info.coords.latitude, lng: info.coords.longitude }
Geocoder.geocodePosition(position).then(res => {
console.warn(res);
const { updateUserState } = this.props;
updateUserState({ position : position, country : res[0].countryCode, city : res[0].adminArea });
this.setState({ position : position, country : res[0].countryCode, city : res[0].adminArea });
})
.catch(err => {
console.warn(err)
alert(JSON.stringify(err));
})
},
error => {
// alert("Sorry, we cann't get your location now, please check your permission!")
alert(JSON.stringify(error));
console.log(error)
},
{
enableHighAccuracy: false,
timeout: 3000,
// maximumAge: 1000,
},
)
}
}
],
{ cancelable: false }
)
}
I am getting the below error:
PERMISSION_DENIED: 1
POSITION_UNAVAILABLE: 2
TIMEOUT: 3
code: 3
message: "Unable to fetch location within 15.0s."
This is my info.plist:
<key>NSLocationAlwaysUsageDescription</key>
<string>This app requires access to you location.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>This app requires access to you location.</string>
please set custom latlong in the emulator, Debug -> Location -> Custom
Location and set custom latitude and longitude and run the app agin
Related
Does anybody hit this error while updating autoupdate for electron application.
It says:
Error: Can not find Squirrel
enter image description here
below is my code:
const server = 'http://10.172.120.67:8081'
// const url = `${server}/update/${process.platform}/${app.getVersion()}`
const url = `${server}/update/`
console.log(url)
autoUpdater.setFeedURL({ url })
autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
console.log("getin")
const dialogOpts = {
type: 'info',
buttons: ['Restart', 'Later'],
title: 'Application Update',
message: process.platform === 'win32' ? releaseNotes : releaseName,
detail: 'A new version has been downloaded. Restart the application to apply the updates.'
}
dialog.showMessageBox(dialogOpts).then((returnValue) => {
if (returnValue.response === 0) autoUpdater.quitAndInstall()
})
})
autoUpdater.on('error', message => {
console.error('There was a problem updating the application')
console.error(message)
})
autoUpdater.on('update-avliable', function (info){
console.log('update-avliable')
})
autoUpdater.on('checking-for-update', function () {
console.log('checking-for-update')
});
console.log("hello electron")
autoUpdater.checkForUpdates();
Try calling the check for updates when the app is ready:
app.on('ready', function() {
autoUpdater.checkForUpdates();
}
I'm trying to use this library: #react-native-community/geolocation
const requestLocationPermission = async (success, failure) => {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION
)
if( granted === PermissionsAndroid.RESULTS.GRANTED ) {
console.log("You can use the location")
Geolocation.getCurrentPosition(
({ coords }) => {
console.log("coords: ", coords)
},
(errObject) => {
console.log("message: ", errObject) // it gets thrown here
}
)
} else {
console.log("You cannot use the location")
}
} catch (err) {
}
}
It prompts user to either allow or deny the app access to their location. After allowing I get this:
{"PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 2, "message": "No location provider available."}
In AndroidMenufest.xml:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Nothing need more just do like this useState(0) for both lat and lang don't provide any string write this Geolocation.getCurrentPosition((data)=>(console.log(data)
//here you can set the states
))
after open the notification from notification center, the application running only splash screen and force close after splash screen. my application in android is normal open the alert. my ios version 12.2. my code is here:
initializeApp()
{
this.platform.ready().then(() => {
if (this.platform.is('cordova'))
{
this.oneSignal.startInit('xxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxx');
this.oneSignal.inFocusDisplaying(this.oneSignal.OSInFocusDisplayOption.Notification);
this.oneSignal.handleNotificationReceived().subscribe(data => this.onPushReceived(data.payload));
this.oneSignal.handleNotificationOpened().subscribe(data => this.onPushOpened(data.notification.payload));
this.oneSignal.endInit();
}
this.statusBar.styleDefault();
this.splashScreen.hide();
});
}
private onPushOpened(payload: OSNotificationPayload) {
let alert = this.alertCtrl.create({
title: payload.additionalData.nodename,
subTitle: 'My Note : '+payload.additionalData.title1+' <br/> '+'My Why : '+payload.additionalData.mywhy,
message: payload.body,
buttons: [
{
text: 'Utsett',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'Det er utført',
handler: () => {
console.log('oke');
this.responseData = result;
this.nav.setRoot(MynotesPage, {id:payload.additionalData.id});
});
}
}
]
});
alert.present();
}
I can't start intent right from "HandleNotificationOpened" function. Can anybody help me with this problem.
I'm following this tutorial to get user's location on iOS React Native app:
https://hackernoon.com/react-native-basics-geolocation-adf3c0d10112
Using this code to get current location:
navigator.geolocation.getCurrentPosition((position) => {
console.log(position); // TBD
this.setState({ location: true });
}, (error) => {
console.log(error); // Handle this
this.setState({ location: false });
}, {
enableHighAccuracy: true,
timeout: 20000,
maximumAge: 1000,
});
But the app crashes at this file:
PermissionsAndroid.js:
const shouldShowRationale = await NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale(
with error:
TypeError: Cannot read property shouldShowRequestPermissionRationale of undefined at PermissionsAndroid.Request$
But I'm not even running on Android - I'm running iOS.
Could this be a RN bug or how I'm using it?
Just had to request permissions first:
await navigator.geolocation.requestAuthorization();
I am able to create pdf in my ionic app and if I run the app in chrome it opens perfectly. However if I install my app on the android device it doesn't open. Below is my code. Can someone please help me if I have to do something extra to open it on device. I want to open it with default pdf application on device.
pdfMake.createPdf(dd).open();
Ok. After banging my head on wall for 3 days I finally found the solution and sharing here so that other people who are facing this issue can get help. I am creating pdf and saving it using cordova file plugin. After successful save I am opening it in default application using cordova file opener plugin. Below is my code.
pdfMake.createPdf(YOUR_DEFINITION_HERE).getBlob(buffer => {
this.file.resolveDirectoryUrl(this.file.externalRootDirectory)
.then(dirEntry => {
this.file.getFile(dirEntry, 'test1.pdf', { create: true })
.then(fileEntry => {
fileEntry.createWriter(writer => {
writer.onwrite = () => {
this.fileOpener.open(fileEntry.toURL(), 'application/pdf')
.then(res => { })
.catch(err => {
const alert = this.alertCtrl.create({ message:
err.message, buttons: ['Ok'] });
alert.present();
});
}
writer.write(buffer);
})
})
.catch(err => {
const alert = this.alertCtrl.create({ message: err, buttons: ['Ok'] });
alert.present();
});
})
.catch(err => {
const alert = this.alertCtrl.create({ message: err, buttons: ['Ok']
});
alert.present();
});
});