Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
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
[doublepost=1459657503][/doublepost]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];
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.