【发布时间】:2018-01-31 02:09:33
【问题描述】:
现在我想编写一个小 CLI 应用程序,它可以获取自定义方案 url 来执行诸如启动其他应用程序之类的操作。 我找到了一个方法, 首先,编辑“info.plist”,在“URL 类型”下添加一个“URL Schemes”,例如我添加一个“mySchemes”项。 其次,在“AppDelegate”中安装一个事件处理程序,
-(void)applicationWillFinishLaunching:(NSNotification *)aNotification
{
NSAppleEventManager *appleEventManager = [NSAppleEventManager sharedAppleEventManager];
[appleEventManager setEventHandler:self andSelector:@selector(handleGetURLEvent:withReplyEvent:)
forEventClass:kInternetEventClass andEventID:kAEGetURL];
}
-(void) handleGetURLEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
{
NSString *url = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
NSLog(@"%@",url);
// Do something next
}
但我想在命令行应用程序中实现它,我如何在没有 cocoa 框架的情况下获取此事件?我不需要用户界面
【问题讨论】:
-
或者在没有 UI 的情况下使用 cocoa
-
您可以拥有一个没有菜单或窗口的可可应用程序...您可以将其作为服务或作为单次应用程序运行...
标签: objective-c macos cocoa