I'm using the cordova-plugin-request-location-accuracy plugin to prompt the user to turn location on (if not already on). However the prompt doesn't show, and I get the following error
Accuracy request failed: error code=4; error message=User chose not to make required location settings changes.
Here is the part of the code I've called the plugin
function init() {
document.addEventListener("deviceready", watchPosition, false);
}
function watchPosition() {
cordova.plugins.backgroundMode.enable(); // enable backgroundMode
// Check if location settings are turned on. Prompt user if not turned on
function onRequestSuccess(success){
console.log("Successfully requested accuracy: "+success.message);
}
function onRequestFailure(error){
console.error("Accuracy request failed: error code="+error.code+"; error message="+error.message);
if(error.code !== cordova.plugins.locationAccuracy.ERROR_USER_DISAGREED){
if(window.confirm("Failed to automatically set Location Mode to 'High Accuracy'. Would you like to switch to the Location Settings page and do this manually?")){
cordova.plugins.diagnostic.switchToLocationSettings();
}
}
}
cordova.plugins.locationAccuracy.request(onRequestSuccess, onRequestFailure, cordova.plugins.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY);
// start geolocation
checkPeriodically = setInterval(checkTime, 10000);
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
...
The rest of the program runs fine (when the location is manually switched on). What is causing this to fail? Thanks.
Related
I had used the health package in flutter for steps and running data in android the google fit and physical activity permission are set perfectly but in iOS, it is not asking for health kit permission all other permissions are working perfectly fine here is the code which I had written for permission request
Future<void> requestActivityPermission() async {
if (Platform.isAndroid) {
final permissionStatus = await Permission.activityRecognition.request();
if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
_activityPermanenetlyDeniedCase();
return;
} else {
permissionStatus.isGranted;
fetchTotalStepData();
}
} else {
final permissionStatus = await Permission.activityRecognition.request();
if (permissionStatus.isDenied || permissionStatus.isPermanentlyDenied) {
_activityPermanenetlyDeniedCase();
return;
} else {
permissionStatus.isGranted;
fetchTotalStepData();
}
}
}
The requestActivityPermission function is called in the initState Method.
The _activityPermanenetlyDeniedCase function directly opens up, in that function i had a dialog box showing open setting, but in the setting there is no healthkit permission.
I am expecting a popup permission for healthKit
You need to specify which permission you are using in Info.plist file under ios/ directory.
<key>NSHealthShareUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
<key>NSHealthUpdateUsageDescription</key>
<string>We will sync your data with the Apple Health app to give you better insights</string>
Refer here
Check that the healthkit is activated in both the debug and release tabs
So I am using flutter-permission-handler to handle all the permission functionality,
for E.G
// Location Permission
askForLocation() async {
// Permission type
var status = await Permission.location.request();
if (status.isGranted) {
_location.value = status.isGranted;
update();
} else {
print('open setting');
openAppSettings();
}
}
work as expected on android but when it comes to ios it always returns permanently denied
however, with that kind of return it should open the app setting page, it opens only the home setting page on the simulator and a physical device.
my first response was to try to get the app from the setting page I couldn't find the app itself.
you can see the behaviour in this video
https://youtu.be/ugpFMFyKhLY
anyone facing the same issue?
I am developing a PWA that requires Push-Notifications. Sadly IOS/Safari does not support https://w3c.github.io/push-api/#pushmanager-interface for now, so I think i might have to wrap a native APP around in some way.
In Android (before their "Trusted Web Activities" was a thing) you could use a WebView to basically display a headless Chrome-View in your App. Whats the equivalent in IOS and how does the interaction between push-notifications and the Webapp (the browser need to jump to a specific page) work?
One more thing I need is integration with our companys Mobile Device Management, which is Microsoft Intune. Having integrated MDMs in Android in the past i Know that this might be a major pain in the a**, so i'm considering to build the wrapper myself, for maximum flexibility. Another option would be something like Ionic, not sure now.
This may not necessarily work in your situation, but I had the exact same issue with a PWA for Safari and I solved it by just using long polling. It will allow you to get around all of the limitations with Safari and I was able to redirect and load sections within our SPA.
async function subscribe() {
let response = await fetch("/subscribe");
if (response.status == 502) {
// Status 502 is a connection timeout error,
// may happen when the connection was pending for too long,
// and the remote server or a proxy closed it
// let's reconnect
await subscribe();
} else if (response.status != 200) {
// An error - let's show it
showMessage(response.statusText);
// Reconnect in one second
await new Promise(resolve => setTimeout(resolve, 1000));
await subscribe();
} else {
// Get and show the message
let message = await response.text();
showMessage(message);
// Call subscribe() again to get the next message
await subscribe();
}
}
subscribe();
https://javascript.info/long-polling
I have a Cordova (vers 9) app that uses phonegap-plugin-push (v2.3.0) on cordova-ios (v4.5.1) that does not register for notifications when run on an iOS device, (iPad mini iOS 9.3.5). I am using Xcode (vers 8) within MacOSX Sierra. The xcode project Capabilities tab has push notifications turned on, the project builds without error and the App ID configuration has Push Notifications enabled with a valid certificate. Additionally, it does not show as having access to notifications in the settings for the app on the iOS device nor does it prompt for access when run.
How do I narrow down where the registration problem is? Does the device I am running it from have anything to do with it? Am I missing a call that requests access to notification in the code? Am I missing an error routine that might let me know what the problem is?
Actions I have taken:
Uninstalled/reinstalled cordova
Uninstalled/reinstalled ios
Uninstalled/reinstalled phonegap-plugin-push
Changed order they are added
Fixed numerous build errors that prevented the app from building or signing.
Placed app into debugger and stepped through Javascript code where register takes place.
Exported provision profile from release build and examined to ensure entitlement is present.
var app =
{
// Application Constructor
initialize: function ()
{
this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function ()
{
console.log( 'mobile-rewards: bindEvents() called' )
document.addEventListener( 'deviceready', this.onDeviceReady, false );
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function ()
{
const push = PushNotification.init(
{
android:
{
},
browser:
{
pushServiceURL: 'http://push.api.phonegap.com/v1/push'
},
ios:
{
alert: "true",
badge: "true",
sound: "true"
},
windows: {}
});
// e.message
push.on('error', function(e)
{
console.log(e.message);
});
push.on('registration', function(deviceInfo)
{
console.log("device info - "+deviceInfo.registrationType+":"+deviceInfo.registrationId);
});
push.on('notification', function(data)
{
console.log(data.message);
});
},
};
// initialize the app.
app.initialize();
I expected the plugin to register successfully but it doesn't appear to have done so. There is no error present coming from the error handler and the plugin appears to function normally. The debug output log from the plugin shows progress through the entire PushPlugin.m code for the init. The exported app shows the aps-environment provision within it for production. However, the application neither returns a registration ID, prompts for notification access, nor shows up as even needing these privileges in the settings.
Where can I find the file object with the getImage API when the iOS location is not allowed by the user?
Will the error callback have the successful file object as shown here?
file.getImage( function (file) { /* the success scenario */ , function (file) { /* the error scenario but still has successful file object */ );
Or will the error callback have both the content and file objects?
file.getImage( function (file) { /* do success scenario */ , function (content, file) { /* error scenario but has successful file object */ );
What would be the proper API pattern for this scenario?
The reason the user might be prompted for location permission when you use file.getImage is because there is location data embedded the image's EXIF metadata which could be used to covertly infer their position.
This only occurs when you read data from the gallery: if you use the saveLocation: "file" parameter to getImage, the user won't be prompted for location permission.
In either case, the success callback for file.getImage should always be invoked with a file object (unless the user cancelled image capture entirely): it's only when you come to use the file that the location permission might be needed.