locked
Custom URL schema handling RRS feed

  • Question

  • User20908 posted

    I'm trying to use custom URL handling. I was managed to setup my custom URL schema and register handler. However I stuck on the place where my handler get called. I didn't find proper way to extract URL. Here is what I see from Objective-C example:

    - (void)handleEvent:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent
    {
        NSString *urlStr = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
    }
    

    paramDescriptorForKeyword: requires AEKeyword enum which defined like this:

    enum {
      /* Keywords for Apple event parameters */
      keyDirectObject               = '----',
      keyErrorNumber                = 'errn',
      keyErrorString                = 'errs',
      keyProcessSerialNumber        = 'psn ', /* Keywords for special handlers */
      keyPreDispatch                = 'phac', /* preHandler accessor call */
      keySelectProc                 = 'selh', /* more selector call */
      /* Keyword for recording */
      keyAERecorderCount            = 'recr', /* available only in vers 1.0.1 and greater */
      /* Keyword for version information */
      keyAEVersion                  = 'vers' /* available only in vers 1.0.1 and greater */
    };
    

    C# analogue from MonoMac defined like

    public virtual NSAppleEventDescription ParamDescriptorForKeyword(uint keyword);

    And I didn't find what keyword (uint) should I pass to the method to make it work like in Objective-C example. After playing a bit, I find the code which work, but it looks not like Objective-C example and uses hard-coded magic constants:

    string urlStr = anEvent.DescriptorAtIndex(1).StringValue;

    Can somebody help me to find proper way to extract URL from passed NSAppleEventDescriptor?

    Monday, November 4, 2013 11:19 AM

Answers

  • User2589 posted

    I never used that specific API but the four characters in enums values are common in Apple API.

    The four characters (4 bytes) are compiled into an integer. If there's no C# enum already available then you can convert the strings to an integer which this code:

    public static int FourCC (string s)
    {
        return (((int)s [0]) << 24 |
                ((int)s [1]) << 16 |
                ((int)s [2]) << 8 |
                ((int)s [3]));
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 7, 2013 10:04 PM

All replies

  • User2589 posted

    I never used that specific API but the four characters in enums values are common in Apple API.

    The four characters (4 bytes) are compiled into an integer. If there's no C# enum already available then you can convert the strings to an integer which this code:

    public static int FourCC (string s)
    {
        return (((int)s [0]) << 24 |
                ((int)s [1]) << 16 |
                ((int)s [2]) << 8 |
                ((int)s [3]));
    }
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, November 7, 2013 10:04 PM
  • User20908 posted

    @SebastienPouliot,

    Perfect! It works! I didn't find existing enum for this. Probably, you as Team member will create internal ticket for that.

    // anEvent comes outside
    // NSAppleEventDescriptor anEvent;
    // ...
    //
    string keyDirectObject = "----";
    uint keyword = (((uint)keyDirectObject [0]) << 24 |
        ((uint)keyDirectObject [1]) << 16 |
        ((uint)keyDirectObject [2]) << 8 |
        ((uint)keyDirectObject [3]));
    
    string urlStr = anEvent.ParamDescriptorForKeyword(keyword).StringValue;
    
    Friday, November 8, 2013 12:36 PM