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://"]];
Related
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 = ....
}
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];
If Apple encounters errors during loadHTMLString, they throw them on a separate thread, with no stacktrace (in Xcode4), and no output to the console.
How do you listen to these errors, debug them, and - ultimately - react to them?
(FYI - I'm using loadHTMLString because I need to load a mix of local and remote resources, and this method provides the only simple way to do it, AFAIAA)
EDIT: ...sorry, to be clear: There are different errors that Apple may encounter. For instance, if it gets an error trying to load an embedded resource (e.g. a CSS file), it won't count that as a "page failed to load", in fact it will report a successful page load.
IMHO ... that is the correct behaviour: if the HTML-parser is able to recover from the error, I don't want "page failed to load". But the errors are still important - they tell us why the page is rendering e.g. without a background image, or with broken images.
For debugging purposes you can attach Safari Web Inspector. To do so:
Make sure you have a version of Safari installed that supports SWI - so at least Safari 6 on Mac OS X 10.7.4.
On the device (or simulator) you're using to test the app, enable Settings > Safari > Advanced > "Web Inspector".
Launch Safari.
Enable Safari > Preferences > Advanced > "Show Develop menu in menu bar".
Run the app and, when the webview you're working with displays, go to Safari > Develop > [device name or "iPhone simulator"] > [web address - it will be listed under the app name]
It will show you what static files have been loaded by the page. (If you want to see Javascript errors, you'll need to attach as normal, set a breakpoint on all exceptions - in SWI, not just in Xcode! - then select the root-level page and CMD+R to reload it.)
As far as I can tell, the only way to do this programmatically (for instance, if you want to retry failed page loads) is with an NSURLProtocol subclass.
Although I haven't used loadHTMLString:, you should be able to register your controller as a UIWebViewDelegate and implement the – webView:didFailLoadWithError: method which should call whenever it fails.
Assign a delegate to your webview and use this method in the delegate.
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
NSLog(#"Error is %#",error);
}
I'm implementing a website call on button touch(in iPhone), so my browser get called in that case and website get opened.
I'm using following code:
- (IBAction) websiteButtonTouched{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"http://www.google.com"]];
}
Now what I want is to COME BACK TO MY APPLICATION FROM BROWSER as In iPhone4.0 and Up the application remain running at background we only have to call that when browser quite...
Thanks In Advance.. :P
Why not create your own in-app browser? Just put a UIWebView inside a navigation controller then put an address bar and a search bar.
Please see this question:
iPhone - Open Application from Web Page
As for returning to application where you left off -- if the device supports backgrounding (iOS4+) and your backgrounded app wasn't unloaded (due to memory shortage), the app will return the point you left it.
However, you also have to handle the returning to correct point in app yourself, in the cases that the device doesn't support backgrounding, or app was unloaded due to memory shortage: you can do this by storing information about current state of the app before it exits.
This web page has some very nice flow charts which describe app backgrounding and foregrounding etc.:
http://www.cocoanetics.com/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging
My application has setting in Settings.
User may change the setting.
After user apply the changes and launch the app. because the application launched before and it support multitask so the changes applied into the setting, will not apply into the application. Unless the user close the task and relaunch the app.
So I would implement if statement into the application to do:
if (settingBool == 1){
'restarted the application'
} else {
'Multitask keep working'
}
Thanks
You could tell your app that there could be new settings in - (void)applicationDidBecomeActive:(UIApplication *)application
Set a flag or send a notification that tells every object that has cached settings to read them again from the NSUserDefaults