如何使用Xamarin.Mac设置和调试URL方案?
我将以下内容添加到我的Info.plist中

然后我构建了一个安装程序包并安装了这个应用程序。但是,如果我在浏览器中打开mytest://或运行open mytest://命令行,则不会启动我的应用程序。
此外,在运行mytest://之后,是否有一种方法可以将调试器附加到Xamarin中?在Windows上,我会使用Debugger.Break和Debugger.Attach,但这些方法似乎不是在Mono中实现的。
发布于 2013-10-19 22:38:39
它没有直接解决您的问题,但是这个问题的答案对您有帮助吗?
具体来说,它使用项目上的自定义执行命令选项来解决问题。您可以定义一个自定义命令,以在调试器中执行应用程序:
打开“项目选项”,进入“Run>Custom命令”部分,为“执行”添加一个自定义命令
它还提到了Debugger.Break行为:
如果您的应用程序在Mono 2.11或更高版本的Mono软调试器中运行,它将为软调试器设置一个软断点,并按预期工作。
编辑:
你可以在一个已经在运行的Mac应用上调用一个URL .您能设置一个处理程序来捕获事件,在里面设置一个断点,并检查您的URL是否正确地调用了已经运行的应用程序?它可能会为您提供有关行为的提示或进一步调试的方法。就像这样:
public override void FinishedLaunching(NSObject notification)
{
NSAppleEventManager appleEventManager = NSAppleEventManager.SharedAppleEventManager;
appleEventManager.SetEventHandler(this, new Selector("handleGetURLEvent:withReplyEvent:"), AEEventClass.Internet, AEEventID.GetUrl);
}
[Export("handleGetURLEvent:withReplyEvent:")]
private void HandleGetURLEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor replyEvent)
{
// Breakpoint here, debug normally and *then* call your URL
}发布于 2015-07-15 09:07:56
正如@TheNextman发布的,该解决方案确实有效,但这是一个更完整的解决方案。我从这 Xamarin论坛的线程中获得了以下信息。如用户(和Xamarin雇员) Sebastien (@poupou)所述,
我从未使用过这个特定的API,但是枚举值中的四个字符在Apple中很常见。 这四个字符(4个字节)被编译成一个整数。如果已经没有可用的C#枚举,那么可以将字符串转换为整数,下面的代码如下: 公共静态int FourCC (string s) {返回(Int)s) << 24 x(Int)s 1) << 16 x ((int)s 2) << 8(Int)s 3);}
所以完整的样本如下,
public override void FinishedLaunching(NSObject notification)
{
NSAppleEventManager.SharedAppleEventManager.SetEventHandler(this, new Selector("handleGetURLEvent:withReplyEvent:"), AEEventClass.Internet, AEEventID.GetUrl);
}
[Export("handleGetURLEvent:withReplyEvent:")]
private void HandleGetURLEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor replyEvent)
{
string keyDirectObject = "----";
uint keyword = (((uint)keyDirectObject[0]) << 24 |
((uint)keyDirectObject[1]) << 16 |
((uint)keyDirectObject[2]) << 8 |
((uint)keyDirectObject[3]));
string urlString = descriptor.ParamDescriptorForKeyword(keyword).StringValue;
}https://stackoverflow.com/questions/19458803
复制相似问题