0

Ive been struggling with a way to retrieve information periodically from a BT device. My bluetooth device is located in a vehicle typically, so my question is if its possible to use say... (if user traveling > 10km/h) to run a task. Or on major location change.

Is is possible to get a really course location that I would be able to use to get a general idea of wether the user is moving? I only need it to trigger once every couple days(while user is driving). The user never interacts with my app after initial setup.

Thanks.

Implementation of cmyr's suggestion:

CLLocationManager *locationManager;
int badge_count = 0;
- (void)startSignificantChangeUpdates
{
    // Create the location manager if this object does not
    // already have one.
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];

    locationManager.delegate = self;

    locationManager.pausesLocationUpdatesAutomatically = YES;

    locationManager.activityType = CLActivityTypeAutomotiveNavigation;

    [locationManager requestAlwaysAuthorization];

    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    locationManager.distanceFilter = 500; // meters

    [locationManager allowDeferredLocationUpdatesUntilTraveled:501 timeout:-1];
    [locationManager startMonitoringSignificantLocationChanges];
    [locationManager startUpdatingLocation];
}
// Delegate method from the CLLocationManagerDelegate protocol.
- (void)locationManager:(CLLocationManager *)manager
     didUpdateLocations:(NSArray *)locations {
         badge_count++;
         [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge_count];
         NSLog(@"Location Event WOOT!");
     }

Unfortunately I cannot get the event to trigger. I have added Location updated to the apps plist.

The above code is contained inside my app delegate.m file

theshadow124
  • 661
  • 3
  • 8
  • 29

1 Answers1

2

Core Location has a set of APIs for specifically this use-case, which Apple refers to as Significant Location Change Monitoring.

From the documentation:

The significant-change location service delivers updates only when there has been a significant change in the device’s location, such as 500 meters or more.

This API only updates your location when and if you've traveled the specified distance. It does not provide constant updates. If you need constant updates, you will have to use the standard location service.

cmyr
  • 2,235
  • 21
  • 30
  • 1
    is there any limitation like... iOS does something like wait and give all the updates at once? Its important for the app to be notified while in the vehicle. Im testing using simulated GPS positions and I can't seem to get it to work. – theshadow124 Dec 04 '14 at 05:40
  • edited. I'd encourage you to read through the documentation if you're unfamiliar, it should answer most of your questions. – cmyr Dec 04 '14 at 16:20
  • I was simulating location changes from city to city to test. Also noticed I don't get a dialog asking permission to use my location. – theshadow124 Dec 04 '14 at 20:28
  • adding plist descriptors as found on this answer fixed my issues: http://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8 – theshadow124 Dec 05 '14 at 03:25
  • guess it didn't solve all my problems, I am only receiving one update and then no more after that. I even drove around the city to see if the simulated GPS was somehow interfering but it still only got one update. – theshadow124 Dec 05 '14 at 04:23
  • again, the significant location change only gives you an update when you've moved a significant location. It does *not* provide constant updates. for that you need to use the normal location services api. – cmyr Dec 05 '14 at 15:27
  • I drove around the city using startUpdatingLocation and it works... but not with just startMonitoringSignificantLocationChanges I've edited my code above. even using startUpdatingLocation has very little impact on battery life so it should be ok, my only concern is if my app would pass the app review stage since I don't exactly NEED frequent updates. – theshadow124 Dec 05 '14 at 19:27