gpt4 book ai didi

objective-c - 如何在 Mac 命令行应用程序中获取自定义 url?

转载 作者:行者123 更新时间:2023-12-03 17:47:19 24 4
gpt4 key购买 nike

现在我想编写一个小型 CLI 应用程序,它可以获取自定义方案 url 来执行诸如启动其他应用程序之类的操作。我找到了一个方法,首先,编辑“info.plist”,在“URL 类型”下添加“URL 方案”,例如我添加一个“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框架的情况下获取此事件?我不需要用户界面

最佳答案

在 Info.plist 中设置 LSUIElement 将允许您在没有 UI 的情况下运行应用程序。来自苹果的Information Property List Key Reference :

If this key is set to YES, Launch Services runs the app as an agent app. Agent apps do not appear in the Dock or in the Force Quit window. Although they typically run as background apps, they can come to the foreground to present a user interface if desired. A click on a window belonging to an agent app brings that app forward to handle events.

关于objective-c - 如何在 Mac 命令行应用程序中获取自定义 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48533391/

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