Strange GPS fix behavior on 3g iPhone - iphone

I wrote an GPS enabled iPhone App that needs about 70m accuracy. In most cases this accuracy is reached after a few seconds waiting. But on some occasions it is never reached. Then I have to restart the iPhone and my app and the fix is acquired immediately.
Some users also told me that starting a different app that uses gps, close that app and starting my app again fixes the problem as well. But I am not so sure if that works, because I couldn't test it myself.
The problem only occurs on 3g iPhones not on the 3gs.
Any idea what is happening or how I can fix this in code, so that I don't have to reboot my iPhone?
edit:
Code that I use:
locationManager = [[CLLocationManager alloc] init];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.delegate = self;
[locationManager startUpdatingLocation];

I'm seeing the same behavior in my own GPS-centric app. The 3G tends to narrow in more slowly than the 3GS. All I can figure so far is that the 3G's GPS got improved for the 3GS.

Related

iOS 7 - didUpdateLocations delegate not called after app goes in background

I'm able to receive location updates on all (simulators and iPad device) but my iPhone device.
self.locationManager = [[[CLLocationManager alloc] init] autorelease];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
self.locationManager.delegate = self;
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *newLocation = locations.lastObject;
NSLog(#"didUpdateLocations newLocation = %#", newLocation);
.
.
}
I receive didUpdateLocations (NSLog message) as long as app is in foreground but after I press Home button (i.e. app goes in background), I stop receiving notifications in didUpdateLocations. The 'console' doesn't show the NSLog message and thereafter even the location icon in status bar goes away within 10 seconds.
What works an what doesn't -
Appears that iOS 6 installed on my other iPhone 3gs works fine. The little location icon doesn't go away.
Test on iPad device with iOS 7 and the app keeps running in background.
All simulators (iPhone and iPad) with iOS 6 as well as iOS 7 works as expected.
When i test it on my iPhone 4 with iOS 7, the app doesn't run in background. So probably, this issue is only on iOS 7 (and even some specific iPhone devices).
I think I found the cause of this problem. The "Settings" app in iOS 7 has General > "Background App Refresh" which was turned OFF :(
As soon as I turned it "ON", my app started running in background :)
The above solution did not work for my particular case in iOS 8.X, therefore, I would like to post the solution that worked for me in hopes that it might help others.
I successfully setup silent Push Notifications which I was receiving in the Foreground, Background, and Suspended states. Once I received the PN I would need to obtain the location updates. I was able to do so while the application was in the Foreground, however, I was not able to do so while the application was in the background.
What I needed to do was add a key to the info.plist file called NSLocationAlwaysUsageDescription and give it a value. The value can be something like "Your location is needed in the background."
After adding the key I then added this code within my AppDelegate.m's application:didFinishLaunchingWithOptions: method -
// Check for iOS 8.X. Without this guard the code will crash with "unknown selector" on iOS 7.
if([[self locationManager] respondsToSelector:#selector(requestAlwaysAuthorization)])
{
[[self locationManager] requestAlwaysAuthorization];
}
Once I added these two pieces I was able to successfully obtain location updates in the background.
Thanks,
audible

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];

Enable Location Services programmatically inside application on iPod Touch

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];
}

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];