简体   繁体   English

Xamarin.Mac URL方案

[英]Xamarin.Mac URL Scheme

How do you setup and debug URL schemes with Xamarin.Mac? 如何使用Xamarin.Mac设置和调试URL方案?

I added the following to my Info.plist : 我在Info.plist添加了以下内容:

的Info.plist

I then built an installer package and installed the app. 然后我构建了一个安装程序包并安装了应用程序。 But if I open mytest:// in a browser or run open mytest:// command line, neither launches my app. 但是,如果我打开mytest://在浏览器或运行open mytest://命令行,无论是启动我的应用程序。

Additionally, is there a way to attach the debugger in Xamarin Studio after running mytest:// ? 另外,运行mytest://后,有没有办法在Xamarin Studio中附加调试器? On Windows I'd use Debugger.Break and Debugger.Attach but those methods don't seem to be implemented in Mono. 在Windows上,我使用Debugger.BreakDebugger.Attach但这些方法似乎没有在Mono中实现。

It doesn't directly address your issue, but does the answer to this question help you at all? 它没有直接解决您的问题,但这个问题的答案对您有帮助吗?

Specifically, it addresses using the custom execution command option on your project. 具体来说,它使用项目上的自定义执行命令选项进行寻址。 You can define a custom command to execute your application in the debugger: 您可以定义自定义命令以在调试器中执行您的应用程序:

Open 'Project Options', got to the 'Run>Custom Commands' section, add a custom command for 'Execute' 打开“项目选项”,进入“运行>自定义命令”部分,为“执行”添加自定义命令

It also mentions the Debugger.Break behaviour: 它还提到了Debugger.Break行为:

If your app is running inside the Mono Soft Debugger with Mono 2.11 or later [...], it will set a soft breakpoint for the soft debugger and work as expected 如果您的应用程序在带有Mono 2.11或更高版本的Mono Soft Debugger中运行[...],它将为软调试器设置软断点并按预期工作


EDIT: 编辑:

You can call a URL on an already running Mac app... Can you set up a handler to trap the event, set a breakpoint inside and check that your URL is calling the already-running app properly? 您可以在已经运行的Mac应用程序上调用URL ...您是否可以设置处理程序来捕获事件,在内部设置断点并检查您的URL是否正确调用已在运行的应用程序? It might give you a clue to the behaviour or a way to further debug. 它可能会为您提供行为的线索或进一步调试的方法。 Something like this: 像这样的东西:

    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
    }

As posted by @TheNextman the solution does work but this is a more complete solution. 由@TheNextman发布,该解决方案确实有效,但这是一个更完整的解决方案。 I got the following information from this Xamarin forums thread. 我从这个 Xamarin论坛帖子中获得了以下信息。 As user (and Xamarin employee) Sebastien Pouliot (@poupou) states, 用户(和Xamarin员工)Sebastien Pouliot(@poupou)说,

I never used that specific API but the four characters in enums values are common in Apple API. 我从未使用过特定的API,但枚举值中的四个字符在Apple API中很常见。

The four characters (4 bytes) are compiled into an integer. 四个字符(4个字节)被编译成整数。 If there's no C# enum already available then you can convert the strings to an integer which this code: 如果没有C#enum已经可用,那么你可以将字符串转换为整数,该代码如下:

 public static int FourCC (string s) { return (((int)s [0]) << 24 | ((int)s [1]) << 16 | ((int)s [2]) << 8 | ((int)s [3])); } 

So the complete sample would be as follows, 所以完整的样本如下,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM