Wondering if someone could help me with this, or at least point me in the right direction.
I've been searching for documentation on how to get/set settings in a React Native iOS app so that those settings appear in the iOS Settings app listed under my app. I see that there is a Settings API, but it appears that the documentation is not complete. The function definitions are listed there, but that's it. No examples or anything.
Can anyone provide me with a simple example, or point me to a tutorial or something that will help me get going? I'm assuming I import Settings from react-native, just like I would do for other APIs, but beyond that I'm not sure where to go.
Thanks.
As stated in React Native documentation :
Settings serves as a wrapper for NSUserDefaults, a persistent
key-value store available only on iOS.
If you want to add iOS Settings bundle to your app you can use this.
As per Chris Sheffield's comment, here is what I have succeeded with so far:
Add a Settings.bundle to your Xcode project
Highlight the project > File > New > File
Choose "Settings Bundle" > Next
I just left the default name: Settings.bundle
Open the Root.plist file inside of the bundle
Make changes based on Apple's documentation (version I'm referencing is archived here: https://web.archive.org/...)
The important value to keep track of is the item's Identifier
Save, compile, and install the app
You can now use Settings.get('<identifier>') like either of these:
const varName = Settings.get('var_name')
const [ varName ] = useState(Settings.get('var_name'));
Notes
I suggest using some method of watching for changes so that your app updates when the user changes settings while it's running, but these are the only parts required.
I do not suggest letting the user also change those specific settings in-app since that goes against the principle of Single Source of Truth, but it's your app, you do what's best for you and your users.
Hope this plugin will help. react-native-permissions
export const _checkPermission = (permissionName) => {
return Permissions.check(permissionName).then(response => {
if (response === 'denied') {
return false
} else if (response === 'authorized') {
return true
} else if (response === 'restricted') {
return false
} else if (response === 'undetermined') {
return false
}
})
}
also, you can use this for asking permission
_requestPermission = (permissionName) => {
return Permissions.request(permissionName).then(response => {
return response
})
}
export const _alertForPermission = (permissionName) => {
return _requestPermission(permissionName)
}
Related
I am using the permission_handler package in flutter to access permissions of the underlying device that my app would run on.
My problem, however, is that the Permission.locationAlways.isGranted always returns false, even when I have changed the permission to "always allow" in the app settings.
Here's the function that checks the phone's permission using the permission_handler package:
void _checkLocationPermission() async {
bool isGranted = await Permission.locationAlways.isGranted;
print("isGranted -- $isGranted");
if (_locationPermissionGranted != isGranted) {
setState(() {
_locationPermissionGranted = isGranted;
});
}
}
This function is called in the initState() method of the screen. I would appreciate any guidance to solve this; it seems pretty simple and I don't know what I am doing wrong.
Make sure you installed the package properly on ios. Modify the podfile appropriately as explained here: here. Also, this video may help, in case you're struggling with the instructions in the previous link: video
I am updating one of our Cordova apps so everything is up-to-date for IOS and Android.
One of the things I ran into for IOS is the requirement that you have to ask for motion permission.
I was able to get the app to ask for the permission, but unlike the other permissions I am unable to customize the text.
The text is now as follows:
"localhost" Would Like to Access Motion and Orientation
But other permissions show the name of my app in stead of "localhost" and a description which I provided in the config.xml
I did provide a description in the config.xml and even added a description manually in the info.plist file in Xcode, but nothing helps.
I am using Ionic 6.9.2, Cordova 9.0.0 and added the ios#5.1.1 platform to Cordova.
Does anyone now how I can provide a description and fix the "localhost" in the Motion permission request?
maybe this is an old issue, but I hope this answer would be helpful.
you need to comment/remove on some block of code on leaflet.locatecontrol inside node_modules folder.
first go to node_modules -> leaflet.locatecontrol -> src and open file L.Control.Locate.js, then comment/remove following code:
if (this.options.showCompass) {
var oriAbs = 'ondeviceorientationabsolute' in window;
if (oriAbs || ('ondeviceorientation' in window)) {
var _this = this;
var deviceorientation = function () {
L.DomEvent.on(window, oriAbs ? 'deviceorientationabsolute' : 'deviceorientation', _this._onDeviceOrientation, _this);
};
if (DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission === 'function') {
DeviceOrientationEvent.requestPermission().then(function (permissionState) {
if (permissionState === 'granted') {
deviceorientation();
}
});
} else {
deviceorientation();
}
}
}
Recently I added Broadcast Upload Extension to Xamarin.Forms project however I can't find a way how to invoke the extension and present it to the user from the container app.
How would I invoke the extension and present it to the user? Through OpenUrl and it's bundle identifier?
Needs to be invoked like this:
var bundle = NSBundle.MainBundle.GetUrlForResource("Foo.iOS.ScreenShareExtensionUI", "appex", "PlugIns");
RPScreenRecorder.SharedRecorder.StartRecording(true, error =>
{
if (error != null)
LogService.Log(error.LocalizedFailureReason, LogService.LogLevel.ERROR, "StartRecording");
});
RPBroadcastActivityViewController.LoadBroadcastActivityViewController(bundle.AbsoluteUrl.ToString(), (controller, error) =>
{
UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(controller, true, null);
RPBroadcastActivityViewController = controller;
});
I think this is repeated somehow here
You need to double-check the NSExtension key.
The value of the NSExtensionPointIdentifier for BroadcastUploadExtension project is written as com.apple.broadcast-services by default
and should be com.apple.broadcast-services-upload
The value of the NSExtensionPointIdentifier for BroadcastUIExtension project is written as com.apple.broadcast-services by default
and should be com.apple.broadcast-services-setupui
Refrence
I have an app that needs to request permanent access to geolocation permission ( also in the background ) to gather data.
At the apps start I do a permission check like so ( simplified )
private static function check():void{
if (Geolocation.permissionStatus == PermissionStatus.GRANTED){
onPermGranted();
}else{
_geo = new Geolocation();
_geo.addEventListener(PermissionEvent.PERMISSION_STATUS, onPermission );
try {
_geo.locationAlwaysUsePermission = true;
_geo.requestPermission();
} catch(e:Error){
onError(e);
}
}
};
private static function onPermission(e:PermissionEvent):void{
trace("GeolocationUtil::onPermission: "+e.status);
};
The first time the app starts and this gets called and works.
Now if I quit the app, then change the permission to "never", and restart the app, I can see that
_geo.requestPermission();
gets called, but there is no response whatsoever and I do not get the iOS permissions dialog as well.
Any ideas? Thanks a lot!
The system will only ask once for the permission even if you uninstall your app and reinstall it again, looks like it has a system level cache,
Try go to Setting -> General -> Reset -> Reset Location & Privacy
I am trying to download a file and save that file in iOS. I am using ionic-native-file plugin to achieve this. The file has been download but i could not find that file in the device.
filewrite = (): void => {
let transfer = this.fileTransfer.create();
let path = "";
let dir_name = 'Download';
let file_name = "Sample.pdf";
if (this.platform.is('ios')) {
this.platform.ready().then(() => {
path = this.file.documentsDirectory;
this.file.writeFile(path,file_name,this.pdfSrc).then((entry) => {
this.showAlert("download completed");
}, (error) => {
this.showAlert("Download Failed.");
}).catch(err=>{
this.showAlert("Download Failed catch.");
this.showAlert(err.message);
});
}
)
}
};
Download completed alert shows and the downloaded path is:
file:///var/mobile/Containers/Data/Application/6DE22F30-5806-4393-830A-14C8A1F320BE/Library/Cloud/Sample.pdf
But i could not find that location in the device. Then, i google and saw here.
cordova.file.documentsDirectory - Files private to the app, but that
are meaningful to other application (e.g. Office files). Note that for
OSX this is the user's ~/Documents directory. (iOS, OSX)
So, i can't see the file actually as it is private to the application. Then i saw in the same link:
So, i tried with the both preference in my config.xml but nothing happened.
Is there any approach to download the file iOS or to dropbox or anywhere else?
I've struggled to find the right directory to save to on different platforms with this cordova plugin too. I landed on using file.externalRootDirectory on Android, and file.cacheDirectory on iOS.
The right location likely depends on what you intend to do with the file. In my case I just needed it stored short-term so I can open it using the user's native PDF reader.