OS X El Capitan: CLLocationManager delegate methods not called

Discussion in 'Mac Programming' started by moonman239, Apr 2, 2016.

  1. moonman239, Apr 2, 2016
    Last edited: Apr 2, 2016

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I don't know why, but my testing indicates that CoreLocation does nothing beyond asking for permission. Edit: This is a command-line program.
    Code:
    #import "LocationGetter.h"
    
    
    
    #ifdef __cplusplus
    
    
    
    usingnamespaceCppLocation;
    
    CppLocationGetter::CppLocationGetter()
    
    {
    
        LocationGetter *getter = [[LocationGetteralloc] initWithCppObject:this];
    
        CFBridgingRetain(getter);
    
        this->getter = (__bridge void *)getter;
    
    }
    
    void CppLocationGetter::startLocationUpdates()
    
    {
    
        [(__bridgeLocationGetter *)getterstartLocationUpdates];
    
    }
    
    #endif
    
    #ifdef __OBJC__
    
    @implementation LocationGetter
    
    {
    
        CppLocation::CppLocationGetter *CppObj;
    
    
    
    }
    
    @synthesize manager = locationManager;
    
    -(instancetype)initWithCppObject:(CppLocationGetter *)getter
    
    {
    
        self = [self init];
    
        if (self) {
    
            CppObj = getter;
    
    
    
            locationManager = [[CLLocationManager alloc] init];
    
            [locationManagersetDesiredAccuracy:kCLLocationAccuracyHundredMeters];
    
            [locationManagersetDelegate:self];
    
        }
    
        returnself;
    
    }
    
    -(void)startLocationUpdates
    
    {
    
    
    
        [locationManagerstartUpdatingLocation];
    
    }
    
    -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(nonnull NSArray *)locations
    
    {
    
        CLLocationCoordinate2D coordinates = [locations.firstObject coordinate];
    
        CppObj->observer->locationUpdated(coordinates.latitude, coordinates.longitude, 100);
    
    }
    
    -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
    
    {
    
        constchar *errorMsg = [error.localizedDescriptioncStringUsingEncoding:NSUTF8StringEncoding];
    
        CppObj->observer->locationFailure(errorMsg);
    
      
    
    }
    
    -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
    
    {
    
        if (status == kCLAuthorizationStatusNotDetermined) {
    
            NSLog(@"Auth status not determined.");
    
            [locationManagerstartUpdatingLocation];
    
        }
    
        elseif (status == kCLAuthorizationStatusAuthorized)
    
        {
    
            NSLog(@"Authorized.");
    
        }
    
        else
    
        {
    
            NSLog(@"Not authorized.");
    
        }
    
    }
    
    @end
    
    #endif
    
    --- Post Merged, Apr 2, 2016 ---
    I now see what I need to do. I need to use a run loop so that my main thread waits until the CLLocationManager thread is finished. After
    Code:
    [locationManager startLocationUpdates]
    
    put either
    Code:
    CFRunLoopRun();
    
    or
    Code:
    [NSRunLoop run];
    
     
  2. albebaubles macrumors regular

    albebaubles

    Joined:
    Feb 9, 2010
    Location:
    Desert Southwest
  3. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.

Share This Page