How to open Location services screen from setting screen?
Step 1: Click on project name >> target>> info >> url Types
Step 2:
-(IBAction)openSettingViewToEnableLocationService:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}
How to open Location Services page in iOS using swift?
I believe this is not possible, you can only navigate to the settings of the app itself; Apple expects the user themself to navigate to location services. . I would recommend giving the user instructions on how to navigate to location services as an alternative such as some screenshots and the path they should take.
Cant open location services screen
Opening a specific sub-screen of Settings programatically no longer works, since iOS 11. Now all you can do is open main screen of Settings App, using url string App-Prefs
How to jump to system setting's location service on iOS10?
Note:I use this method for a long time and everyting goes well,but today(2018-9-14),I had been rejected.
Here is my previous answer,do not use this method forever:
CGFloat systemVersion = [[UIDevice currentDevice].systemVersion floatValue];
if (systemVersion < 10) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]];
}else{
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]
options:[NSDictionary dictionary]
completionHandler:nil];
}
Now I use this way:
if (@available(iOS 10.0, *)) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:[NSDictionary dictionary] completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
Xamarin iOS how to check if Location Services is off or app level device location is off
To check the Device level location permission:
bool deviceLevel = CLLocationManager.LocationServicesEnabled;
Document here: determining_the_availability_of_location_services
To check the app level location permission:
public void CheckAuthorization(CLLocationManager manager, CLAuthorizationStatus status)
{
switch (status)
{
case CLAuthorizationStatus.Authorized | CLAuthorizationStatus.AuthorizedAlways | CLAuthorizationStatus.AuthorizedWhenInUse:
Console.WriteLine("Access");
break;
case CLAuthorizationStatus.Denied | CLAuthorizationStatus.NotDetermined | CLAuthorizationStatus.Restricted:
Console.WriteLine("No Access");
break;
default:
Console.WriteLine("No Access");
break;
}
}
Document here: clauthorizationstatus
Update:
Have a look at answers in there two threads: how-to-programmatically-open-settings-privacy-location-services-in-ios-11 and how-to-open-location-services-screen-from-setting-screen
There says
Avoid use of "prefs:root" or "App-Prefs:root" in you app, otherwise
App will be rejected from App Store. Just open Setting page.
You can not open the device location permission directly, it is not allow through App Store rules.
Just use UIApplication.OpenSettingsUrlString;
to open the setting page.
Opening Location Settings Page or Prompting user to Enable Location
so after going through several tutorials and answers all over the internet i finally was able to find to accomplish what i wanted to achieve,
i used a dependency service as one of the answers indicated here How to open setting from our application in xamarin
there are few things that were not mentioned like registering the interface in order to use it in platform specific projects.
here is the code for anyone who needs it
the Interface :
I called my Interface ILocSettings.cs
using System;
using System.Collections.Generic;
using System.Text;
[assembly: Xamarin.Forms.Dependency(typeof(DE2.ILocSettings))]
namespace DE2
{
public interface ILocSettings
{
void OpenSettings();
}
the form that has a button I called it DataEntryForm
DataEntryForm.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="DE2.DataEntryForm"
>
<ContentPage.Content>
<StackLayout>
<Button x:Name="TurnLocationOn"
Text="Turn On Location"
Clicked="TurnLocationOn_OnClicked"/>
</StackLayout>
</ContentPage.Content>
</ContentPage>
then the DataEntryForm.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
using Plugin.pbXSettings;
using Plugin.Geolocator;
using Plugin.Permissions;
using Plugin.Permissions.Abstractions;
using Plugin.DeviceInfo;
using Plugin.DeviceInfo.Abstractions;
[assembly: Xamarin.Forms.Dependency(typeof(DE2.ILocSettings))]
namespace DE2
{
using Xamarin.Forms.PlatformConfiguration;
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class DataEntryForm : ContentPage
{
public DataEntryForm ()
{
InitializeComponent ();
}
private async void TurnLocationOn_OnClicked(object sender, global::System.EventArgs e)
{
var myAction = await DisplayAlert("Location", "Please Turn On Location", "OK","CANCEL");
if (myAction)
{
if (Device.RuntimePlatform == global::Xamarin.Forms.Device.Android)
{
//DependencyService.Get<ISettingsService>().OpenSettings();
global::Xamarin.Forms.DependencyService.Get<global::DE2.ILocSettings>().OpenSettings();
}
else
{
DisplayAlert("Device", "You are using some other shit", "YEP");
}
}
else
{
DisplayAlert("Alert","User Denied Permission","OK");
}
//
}
}
}
Then I have this Class Placed on the Android Specific Platform LocationZ.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Locations;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Xamarin.Android;
using Xamarin.Forms;
using DE2;
using DE2.Droid;
//[assembly: Xamarin.Forms.Dependency(typeof(ILocSettings))]
//Notice the use of LocationZ in registering below instead of ILocSettings
[assembly: Xamarin.Forms.Dependency(typeof(LocationZ))]
namespace DE2.Droid
{
using System.Runtime.Remoting.Messaging;
using Android.Support.V4.View;
using Android.Support.V7.App;
using Xamarin.Forms;
using DE2;
public class LocationZ : ILocSettings
{
public void OpenSettings()
{
LocationManager LM = (LocationManager)Forms.Context.GetSystemService(Context.LocationService);
if (LM.IsProviderEnabled(LocationManager.GpsProvider)==false)
{
Context ctx = Forms.Context;
ctx.StartActivity(new Intent(Android.Provider.Settings.ActionLocationSourceSettings));
}
else
{
//this is handled in the PCL
}
}
}
}
`
Opening the Settings app from another app
As mentioned by Karan Dua this is now possible in iOS8 using UIApplicationOpenSettingsURLString
see Apple's Documentation.
Example:
Swift 4.2
UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)
In Swift 3:
UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)
In Swift 2:
UIApplication.sharedApplication().openURL(NSURL(string:UIApplicationOpenSettingsURLString)!)
In Objective-C
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Prior to iOS 8:
You can not. As you said this has been covered many times and that pop up asking you to turn on location services is supplied by Apple and not by the App itself. That is why it is able to the open the settings application.
Here are a few related questions & articles:
is it possible to open Settings App using openURL?
Programmatically opening the settings app (iPhone)
How can I open the Settings app when the user presses a button?
iPhone: Opening Application Preferences Panel From App
Open UIPickerView by clicking on an entry in the app's preferences - How to?
Open the Settings app?
iOS: You’re Doing Settings Wrong
Related Topics
How to Add Constraint Between a View and the Top Layout Guide in a Xib File
Uiscrollview's Origin Changes After Popping Back to the Uiviewcontroller
What's Dead & Exploded in Swift's Exception Stack
Facebook Share Content Only Shares Url in iOS 9
Creating a 3X3 Grid with Auto Layout Constraints
Detecting Active Avaudiosessions on iOS Device
iOS Tesseract Ocr Image Preperation
Xcode 8, iOS 10 - "Starting Webfilter Logging for Process"
How to Open Location Services Screen from Setting Screen
iOS 9 - "Attempt to Delete and Reload the Same Index Path"
iOS - Uiimagewritetosavedphotosalbum
Nsuserdefaults Unreliable in iOS 8
iOS App Deployment Without Appstore
Create a Button Programmatically and Set a Background Image
A Launch Storyboard or Xib Must Be Provided Unless the App Requires Full Screen