iOS HTTP request while in background

It can be done but it is unreliable because you ask the OS for time to send something and it can accept or deny your request. This is what I have (stolen from somewhere on SO): […] //we get the new location from CLLocationManager somewhere here BOOL isInBackground = NO; if ([UIApplication sharedApplication].applicationState == UIApplicationStateBackground) … Read more

iOS GPS tracking app that runs all the time

You have two options here: 1) Regular location tracking. This type of tracking works with kCLAuthorizationStatusAuthorizedWhenInUse and kCLAuthorizationStatusAuthorizedAlways authorizations. When CLLocationManager started tracking location once it will receive location updates in delegate method locationManager:didUpdateLocations:. App can go to suspended state, but when location manager receive new location app goes to background state and handles new … Read more

Moving a CLLocation by x meters

A conversion to Swift, taken from this answer: func locationWithBearing(bearingRadians:Double, distanceMeters:Double, origin:CLLocationCoordinate2D) -> CLLocationCoordinate2D { let distRadians = distanceMeters / (6372797.6) // earth radius in meters let lat1 = origin.latitude * M_PI / 180 let lon1 = origin.longitude * M_PI / 180 let lat2 = asin(sin(lat1) * cos(distRadians) + cos(lat1) * sin(distRadians) * cos(bearingRadians)) let … Read more

How can I prompt the user to turn on location services after user has denied their use

With iOS8, you can finally link user to Settings app via openURL. For example, you can create a UIAlertView with a single button that takes user to the Settings app: UIAlertView *alert = [[UIAlertView alloc] initWithTitle:ICLocalizedString(@”LocationServicesPermissionTitle”) message:ICLocalizedString(@”LocationPermissionGeoFenceMessage”) delegate:self cancelButtonTitle:@”Settings” otherButtonTitles:nil]; [alert show]; In your UIAlertView delegate: – (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES]; [[UIApplication … Read more

Why the CLLocationManager delegate is not getting called in iPhone SDK 4.0?

I had a similar error, and is solved now. The issue is declaring locationManager variable locally. Declare it instead as a class variable and make sure it is retained either directly or via property retain (or strong if you use ARC). That solves the problem! The issue was de locationManager variable was released and never … Read more

How to get Location user with CLLocationManager in swift?

first add this two line in plist file 1) NSLocationWhenInUseUsageDescription 2) NSLocationAlwaysUsageDescription Then this is class working complete implement this import UIKit import CoreLocation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { var window: UIWindow? var locationManager: CLLocationManager! var seenError : Bool = false var locationFixAchieved : Bool = false var locationStatus : NSString = “Not … Read more

How to find your current location with CoreLocation

You can find your location using CoreLocation like this: import CoreLocation: #import <CoreLocation/CoreLocation.h> Declare CLLocationManager: CLLocationManager *locationManager; Initialize the locationManager in viewDidLoad and create a function that can return the current location as an NSString: – (NSString *)deviceLocation { return [NSString stringWithFormat:@”latitude: %f longitude: %f”, locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude]; } – (void)viewDidLoad { locationManager = [[CLLocationManager alloc] … Read more