In a CLI Cocoa application, how does one implement a event loop?
I have a Delegate class that handles responses from CLLocationManager and prints them via printf(). Is there some type of busy loop I can put in main() so that the program stays open and keeps CLLocationManager connected to Delegate happily processing 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];
开发者_如何学Go CLLocationManager *locationManager;
locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = del;
[locationManager startUpdatingLocation];
// Something goes here
[pool drain];
return 0;
}
This is what NSRunLoop is for, and CLLocationManager is explicitly documented as requiring one (search for “run loop” on that page), so that's what you need to do: Run the run loop.
精彩评论