Location change app
I have an application that successfully uses significant location changes but has problems starting from loading in a very specific scenario.
- The application starts if the iPhone is unlocked within 3 minutes after downloading.
- However, if I wait more than 3 minutes to unlock my iPhone, the app won't launch. (even if I travel a considerable distance).
It should be noted that the life360 and Facebook apps restart important location changes if the phone is unlocked after the 3 minute mark. The following locationd tag flies after unlocking the phone:
Nov 24 16:43:41 my-iPhone locationd[64] <Notice>: client 'com.life360.safetymap' starting significant location changes
Are there any changes I can make to my implementation of the meaningful location changes code so that the app reliably starts on boot (or at least when the phone is unlocked)?
1) the myapp-info.plist file contains entries for
- "Application registers for location updates" for required backgrounds.
- "location-services" for the required device capabilities
- explanation text for NSLocationAlwaysUsageDescription
2) The following code is an excerpt from my AppDelegate.m.
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
[LogPhoneEvent logPhoneEvent:@"APPLICATION DID FINISH LAUNCHING WITH OPTIONS"];
[LocationManagement startSignificantChangeUpdates];
CGRect screenBounds = [[UIScreen mainScreen] bounds];
#if __has_feature(objc_arc)
self.window = [[UIWindow alloc] initWithFrame:screenBounds];
#else
self.window = [[[UIWindow alloc] initWithFrame:screenBounds] autorelease];
#endif
self.window.autoresizesSubviews = YES;
#if __has_feature(objc_arc)
self.viewController = [[MainViewController alloc] init];
#else
self.viewController = [[[MainViewController alloc] init] autorelease];
#endif
// Set your app start page by setting the <content src='foo.html' /> tag in config.xml.
// If necessary, uncomment the line below to override it.
// self.viewController.startPage = @"index.html";
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
// NOTE: To customize the view frame size (which defaults to full screen), override
// [self.viewController viewWillAppear:] in your view controller.
[self.viewController setLaunchOptions:launchOptions];
// }
return YES;
}
and here are the location management files:
LocationManagement.h
#import <CoreLocation/CoreLocation.h>
#import "LogPhoneEvent.h"
@interface LocationManagement : NSObject <CLLocationManagerDelegate>
+ (void)startSignificantChangeUpdates;
+ (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;
+ (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;
@end
and LocationManagement.m
//
// LocationManagement.m
//
#import "LocationManagement.h"
@implementation LocationManagement
CLLocationManager* locationManager;
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
+ (void)startSignificantChangeUpdates
{
// Create the location manager if this object does not
// already have one.
NSLog(@"LocationManagement attempting startSignificantChangeUpdates");
if (nil == locationManager){
locationManager = [[CLLocationManager alloc] init];
[LogPhoneEvent logPhoneEvent:[NSString stringWithFormat:@"startSignificantChangeUpdates creating new CLLocationManager"]];
}
[locationManager setDelegate:(id)self];
if ([CLLocationManager significantLocationChangeMonitoringAvailable]){
NSLog(@"LocationManagement significantLocationChangeMonitoring IS AVAILABLE");
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0.0")){
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
{
[locationManager requestAlwaysAuthorization];
}
}
[LogPhoneEvent logPhoneEvent:[NSString stringWithFormat:@"startSignificantChangeUpdates START MONITORING SIGNIFICANT LOCATION CHANGES"]];
[locationManager startMonitoringSignificantLocationChanges];
//[locationManager startUpdatingLocation];
NSLog(@"my-uBox LocationManagement starting significant change updates");
}
else{
[LogPhoneEvent logPhoneEvent:[NSString stringWithFormat:@"startSignificantChangeUpdates significantLocationChangeMonitoring NOT AVAILABLE"]];
NSLog(@"my-uBox LocationManagement significantLocationChangeMonitoring NOT AVAILABLE");
}
}
+(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
CLLocation *newLocation = [locations lastObject];
[LogPhoneEvent logPhoneEvent:[NSString stringWithFormat:@"locationmanager DID UPDATE LOCATION to %@", newLocation]];
NSLog(@"LocationManagement didUpdateLocations to %@", newLocation);
}
+(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"LocationManagement didFailWithError %@", error);
[LogPhoneEvent logPhoneEvent:[NSString stringWithFormat:@"locationmanager DID FAIL WITH ERROR %@", error]];
}
@end
I am using iOS 8.1.1 on an Iphone 5 and have been stuck on it for days. Any input would be appreciated.
source to share
No one has answered this question yet
Check out similar questions: