Enable Location Services programmatically inside application on iPod Touch - iphone

I have an iOS application that uses GPS for Location Services. A user would like to use the app on an iPod Touch with an external GPS, but the problem is that the user can't enable Location Services in Settings->General Settings->Location Services for this app.
When the app is run on an iPhone, in Settings->General Settings->Location Services, the app shows up with a toggle switch to enable/disable Location Services for this app. But when the app is run on an iPod Touch, the app doesn't show up in Settings->General Settings->Location Services.
Does anyone know what I need to do programmatically to cause Location Services for this app to show up with a toggle switch in Settings->General Settings->Location Services when run on an iPod Touch?

I think that the ability comes when CLLocationManager is implemented for the first time. I'm not sure if that is what's used with an external GPS receiver but if you're getting the Lat/Long from the GPS, you can send those coordinates to the location manager.

I figured out what the problem was. I had the following code that only allowed Location Services for iPhone and not for iPod. Oops!
if([model hasPrefix:#"iPhone"]){
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.distanceFilter = 10.0f;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
self.locations = [NSMutableArray arrayWithCapacity:32];
}

Related

Allow location service in iPhone

i am making an app in which I want user's location. I am using this code -
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
If user's don't allow there location then next time when user's open app then I am using this code for allow user's location -
if([CLLocationManager locationServicesEnabled] &&
[CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
NSLog(#"enable");
}
else {
NSLog(#"disable");
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"prefs:root=LOCATION_SERVICES"]];
}
But this is not work in iOS SDK 5.1 . So I want that every time when app become in foreground then if location service is disable then how to gave pop up of Allow location service.
The settings app URL scheme is not longer available, you will just have to present the user with an UIAlertView or present a UIViewController modally that tells the user to switch on the location services for your app.
You can't really force the allow location dialog, it just pops up the first time.

how to use Cell tower triangulation in iphone?

In my app, I dont want to work off of location services. I want to get coordinates using Cell tower triangulation on the iphone.
Please tell me how to do this?
Use API called startMonitoringSignificantLocationChanges. From Apple docs -
startMonitoringSignificantLocationChanges service offers a significant
power savings and provides accuracy that is good enough for most
applications. It uses the device’s cellular radio to determine the
user’s location and report changes in that location, allowing the
system to manage power usage much more aggressively than it could
otherwise.
So in code this is how it would look -
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
locationManager.delegate = self;
[locationManager startMonitoringSignificantLocationChanges];

Location Based Notifications are not calling in suspend mode

I am new to location based applications.
My requirement is, device has to show the location based notifications when the user reaches the selected region.
I implemented perfectly. This app is working on background also.
Now my new requirement is, device has to show the location based notifications even after kill the app. [I saw a couple of iPhone apps working with this functionality. The apps are "Reminder" & "Locationizer" ] .
Can you please check my implementations steps as follows.
Launch the application.
Selected the location alert button.
Called the following CLLocationManager API's to monitor my region.
[locationManager startMonitoringForRegion:#"MyRegion" desiredAccuracy:kCLLocationAccuracyBest];
[locationManager startMonitoringSignificantLocationChanges];
Quit the app [Running in background].
I am getting location based alert notifications properly.
Here the new requirement.
Launch the application.
Selected the location alert Button.
Called the following CLLocationManager API's to monitor my region.
[locationManager startMonitoringForRegion:#"MyRegion" desiredAccuracy:kCLLocationAccuracyBest];
[locationManager startMonitoringSignificantLocationChanges];
Kill the app. [now application is not running in background]
App should show the location based notification when user reach the location.
How do I implement this logic?
Hi Friends I found solution for this issue.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
id locationValue = [launchOptions objectForKey:UIApplicationLaunchOptionsLocationKey];
if (locationValue)
{
[self initLocationMonitoring]; // this will invoke CLLocationManager
}
return YES;
}
An app that is quitted cant perform any functioning...so i will suggest to recheck those apps ..they must be functioning in the background to check the location of the device...they won't be able to alert if they are quitted.

Can we turn on/off the GPS programmatically in iPhone?

I want to know can we turn on/off the GPS programmatically in iPhone?
A simple example:
//Init location manager
CLLocationManager* locationManager = [ [ CLLocationManager alloc] init];
locationManager.delegate = self; //we must implement the protocol
//Choose your accuracy level
//To turn on gps (if it isn't on already)
[locationManager startUpdatingLocation];
//To turn gps off (if no other apps are listening)
[locationManager stopUpdatingLocation];
There is more than this, and you can monitor more or less accuracy, and even use wifi/ cell towers. Please read the example first for best usage.
Previous to iOS 5 the behavior was not consistent for launch of phone setting from third party application, but in iOS5 this is improved.
If we are calling startUpdatingLoaction method as below code and if location service is off,the system alert will popup and if we tap setting button,it will navigate to phone setting.
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
Well the GPS will be turned on if you use the CLLocationManager.
The locationmanager will first start by getting the location via triangulation and then turn the GPS to get a more precise fix.

Can we launch setting screen any no of time in iPhone to enable the GPS?

I have tried the launch the settings of iPhone in my application using the call
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];
[locationManager release];
but I was able to launch only once,now I am not able to launch the settings in my application.
I am using iPhone 3GS with iOS 4.2
Is there any other way to launch settings any no of time if the location services are off.
but I was able to launch only once,now I am not
If you saw an alert kind of msg on your app asking for your permission for using yous gps location. Then this is the default behavior of iPhone OS. if you try to get gps location in any app the OS ask for user's permission. You can not launch this alert again!
but if you wants to change the setting (means wants to enable or disable the location tracking) then you can open the "Settings" application and look for location services setting. You can find your app there and disable the location tracking. But remember you can not open the "Settings" app using your app.
Now this issue is not in iOS5.
If you are calling startUpdatingLoaction method as below code and if location service is off,the system alert will popup and if you tap setting button,it will navigate to phone settings screen. And in phone setting screen you can switch on the location service.
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
[locationManager startUpdatingLocation];