I don't know why, but my testing indicates that CoreLocation does nothing beyond asking for permission. Edit: This is a command-line program.
[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
put either
or
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
Code:
[locationManager startLocationUpdates]
Code:
CFRunLoopRun();
Code:
[NSRunLoop run];
Last edited: