开发者

iOS - Maps Application vs other location-aware third party applications

In Maps application that comes bundled with the iPhone, we always get the following alert message whenever the Location services is turned off and the user tries to use location services:

Turn On Location Services to Allow "Maps" to Determine Your Location | Settings | Cancel

Please note that the two buttons in the above Alert are Settings and Cancel.

Now the question is if we can get the exact same behavior as described above in the location-aware third-party applications that we all develop. Just to explain the question in more detail, let us say that we are developing our location-aware application by name "Abc". Every time we invoke that part of "Abc" application that requires location services, we need to get the following alert message, if location services is turned off.

Turn On Location Services to Allow "Abc" to Determine Your Location | Settings | Cancel

I did try the following piece of code in my location-aware application as part of the implementation file, but it does not behave the same way as Maps application in terms of displaying the desired Alert message asking the user to turn on Location services, if it was presently turned off.

@implementation LocationViewController
@synthesize locationManager

self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
locationManager.delegate = self;
[locationManager startUpdatingLocation];

In the related header file, i have the following piece of code

@interface LocationViewController:UIViewController<CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
}
@property(nonatomic, retain) CLLocationManager *locationManager;
@end

Is the开发者_开发百科re some other API(s) that need to be used to get the above described behavior (as in Maps application) OR is it simply not possible for third-party location-aware applications to achieve the desired behavior as of iOS 4.x. Please share your comments on this.


You can't do it - it's a private API. There's no way to launch the settings apps programmatically from within your application (unfortunately, because you can launch iTunes, Safari, and the like through URL schemas. None exist for the settings app). What you get instead is the default "Would you like to use your current location" message.


You can check CLLocationManager's locationServicesEnabled property to see if you have rights generally on the CoreLocation framework.

If not, and you can't operate without them, you need to bellyache to the user about it. You won't be able to give them a one-button launch into the settings app (that's not a published URL scheme), but you can give them instructions how to go there themselves and give you location privileges.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜