gpt4 book ai didi

objective-c - 在 CLI Cocoa 应用程序中,如何实现事件循环?

转载 作者:搜寻专家 更新时间:2023-10-30 20:23:24 24 4
gpt4 key购买 nike

我有一个委托(delegate)类,它处理来自 CLLocationManager 的响应并通过 printf() 打印它们。我可以在 main() 中放入某种类型的繁忙循环,以便程序保持打开状态并保持 CLLocationManager 连接到 Delegate 愉快地处理事件吗?

#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;
}

最佳答案

这就是 NSRunLoop 的用途,CLLocationManager明确记录为需要一个(在该页面上搜索“run loop”),所以这就是您需要做的:运行 run loop。

关于objective-c - 在 CLI Cocoa 应用程序中,如何实现事件循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3373044/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com