Re-enabling location services for iPhone app - iphone

I have been struggling with the location service request for my iPhone app. If the user says "Don't allow", I'm stuck in my "this app needs location services in order to work"...
All attempts to re-apply for location services have been fruitless, which several stacks here can testify to.
Then I read that the only way to re-enable the location services was to redirect the user to the location service settings using this :
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=LOCATION_SERVICES"]];
But even that doesn't seem to work (iPhone 4 and 4S, both on 5.1)
Is there really no other way, except telling the user to go to preferences and then guiding him through ? It seems so toe-twistingly bulky to me.

If the user turned the location service off, there is no other way then to tell the user to turn them on again.
You could try to redirect, but this is only possible on iOS 5.0. So you can do it like:
NSURL *prefsURL = [NSURL URLWithString:#"prefs:root=LOCATION_SERVICES"];
if ([[UIApplication sharedApplication] canOpenURL:prefsURL]) {
[[UIApplication sharedApplication] openURL:prefsURL];
} else {
// Can't redirect user to settings, display alert view
UIAlertView *alertView = ....
}

Related

Detecting programmatically an installed app

I am trying to detect installed Instagram on my device , formerly I used this code to detect an app , but it seems it does not work with iOS 6 or non-JB devices :
NSString *filePath = #"/Applications/Instagram.app";
if ([[NSFileManager defaultManager] fileExistsAtPath:filePath])
{
[self checkingInstalledApp];
}
else
{
NSLog(#"no instagram installed");
}
I check this question but his answer gives me a lot errors ! any solution ?
This is invalid code for two reasons.
1) It attempts to interact with an area outside of its sandbox.
2) It relies on an undocumented implementation detail (Perhaps the install location has moved or the application name has changed?)
What you need to do is use the canOpenURL: method on UIApplication to determine if the system can launch an application via its custom scheme (note: If the App has no custom scheme then you are out of luck)
Custom URL Scheme Opening instagram://, followed by one of the following parameters, will open our app and perform a custom action.
For example, for camera, you would direct users on the iPhone to the
custom URL instagram://camera.
NSURL *instagramURL = [NSURL URLWithString:#"instagram://location?id=1"];
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
[[UIApplication sharedApplication] openURL:instagramURL];
}
From Instagram iPhone Hooks

Navigate to settings screen in iphone

I want to move from my app to settings screen of iphone when a button in the app is pressed. Can any one please help by telling how to do it? Any help is appreciated. Sorry for my bad english.
Thanks
prefs:root=General pattern no longer works for iOS Latest versions !!!
There is an update in it. The following works fine in iOS 8 ..
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=General"]];
you may look at this
iOS Launching Settings -> Restrictions URL Scheme
Settings screen can be opened for versions less than IOS 5.0 as it has been disabled for latest IOS's. For Lower versions you can try this:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs://"]];
MoreOver you should create your own view and present the editable settings to the user and get the input from him(for the first time or as a menu) and store it using NSUserdefaults.
You can't ask user to enter settings such as server-address port etc and try it each time, if it works.
I have found a solution for navigating from your application to Settings application which works fine iOS 8 or later versions
1) [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
This will navigate to settings only if your app settings are absent
if they are present then the above code will navigate to Settings page of your app
I am using the below string to navigate to iCloud page and it works fine
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:#"App-Prefs:root=CASTLE"] options:#{} completionHandler:nil]
just by replacing the "CASTLE" with "GENERAL"

Access Settings app in iOS

Is there an opportinity to show up the settings.app in iOS by clicking on a button? It should work with iOS 5.1 so the "prefs:root..." url is no option.
Do you have an idea how to solve this?
I know the question is about 5.1 specifically, but in case anyone else is interested:
As of iOS 8, it is possible to take a user from your app directly into the Settings app. They will be deep linked into your app's specific Settings page, but they can back out into the top level Settings screen.
UPDATE:
Thanks to Pavel's comment, I simplified the if statement and avoided the EXC_BAD_ACCESS on iOS 7.
UPDATE 2:
If your deployment target is set to 8.0 or above, Xcode 6.3 will give you the following warning:
Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true
This is because the feature was available starting in 8.0, so this pointer will never be NULL. If your deployment target is 8.0+, just remove the if statement below.
if (&UIApplicationOpenSettingsURLString != NULL) {
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:appSettings];
}
You are not able to do this on iOS 5.1. Most likely Apple removed that ability intentionally (you'll get "Please enter a valid URL", while Twitter can still call the Settings, though). Please refer to:
How to open preferences/settings with iOS 5.1?.
Apple Disables Home Screen Shortcuts For Settings Toggles In iOS 5.1
On iOS 8 Apple gave us the possibility to go to the App Settings right from our app
you can apply this code:
- (IBAction)openSettings:(id)sender {
BOOL canOpenSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canOpenSettings) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}
iOS6 shows an option to open the settings app directly from an 'AlertView' (shown automatically) if it detects if you're trying to post to FB or Twitter without having those accounts setup.
I have elaborated this over here
The method openURL: is now deprecated.
iOS 10 +
The correct way to open the settings URL (or any URL for that matter) is as follows:
NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:settingsURL options:#{} completionHandler:^(BOOL success) {
// Do anything here
}];

How to navigate to Location Services setting in an app

When a user whose location services are off, goes to a page that needs Location, a UIAlertView would appear, and at the bottom, there is a button named "Setting". When "setting" is clicked, it would jump to System Setting - Location Service.
What's the button action, or the URI for navigating to Location Services?
iOS doesn't provide an explicit way or URL to navigate to the Settings page.
As far as Location services are concerned, whenever an app tries to use location services, if the "Location Services" in the settings page is set to NO, iOS prompts an alertView for the user to enable (set YES) the option. On subsequent launches, if this option is set to YES, the user will not get this alertView.
All you need to do is to modify your Info.plist file to include location-services in your UIRequiredDeviceCapabilities entry
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=LOCATION_SERVICES"]];
You can do the above, but I don't know whether the App will pass through Apple's app review.If you know, please tell me.
Reference: jump to setting interface in iOS.
This will lead you to app setting page..Were you can change the Setting for you application including Location service..
NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:appSettings];

iPhone - display the "location need to be available" dialog

Testing on the device (Iphone 4, IOS 4.2.1), when you use MapKit / CLLocationManager, there is a standard dialog that asks the user to enable the location settings, and propose a button to go to that settings.
If you click "OK", then this dialog never seems to appear again ?
How can I make it appear again programmaticaly to help the user to got to the correct settings view through that dialog ?
Well, it's not possible to programmatically bring up standard dialog asking user to allow your app using location services. It's all done by iOS.
However, you can always try starting location updates via startUpdatingLocation method on CLLocationManager instance. If location services are disabled, you'll get notified about error condition by delegate and then you can bring up the dialog asking user to go into Settings and enable location services for your app... See below code for filtering kCLErrorDenied.
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)inManager didFailWithError:(NSError *)inError{
if (inError.code == kCLErrorDenied) {
NSLog(#"Location manager denied access - kCLErrorDenied");
// your code to show UIAlertView telling user to re-enable location services
// for your app so they can benefit from extra functionality offered by app
}
}
Please note that you cannot launch Settings app via URL-scheme from your application.
UPDATE: starting from iOS5.1, you can not use the following method.
UPDATE: starting from iOS5, you can launch Settings from your application:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs://"]];