In a Cocoa CLI application, how to implement an event loop?

I have a Delegate class that processes responses from CLLocationManager and prints them through printf (). Is there any type of busy cycle I can add to main () so that the program stays open and supports the CLLocationManager associated with the delegate, happily handling events?

#import <Foundation/Foundation.h>
#import "Delegate.h"
#import <CoreLocation/CoreLocation.h>

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    Delegate *del = [Delegate alloc];

    CLLocationManager *locationManager;
    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = del;
    [locationManager startUpdatingLocation];

    // Something goes here

    [pool drain];
    return 0;
}
+3
source share
1 answer

This is what for NSRunLoop for CLLocationManager it’s explicitly documented as requiring one (search for the “run loop” on this page), so you need to do: Run the run loop.

+2
source

Source: https://habr.com/ru/post/1757374/


All Articles