开发者

In a CLI Cocoa application, how does one implement a event loop?

开发者 https://www.devze.com 2023-01-09 19:54 出处:网络
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 CLLocat

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消