开发者

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://"]];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜