Forum Xamarin.iOS

Xamarin.Mac TouchBar "straight from master" dev build available

ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

There has been significant interest in the new Cocoa "TouchBar" APIs Apple introduced, so I figured people might be interested in a pre-preview.

This is a build of Xamarin.Mac straight from master itself. It has had literally none of the standard QA and should not be considered officially supported, stable, or even totally useable.

However, it is the fastest way to check out the new APIs.

https://bosstoragemirror.blob.core.windows.net/wrench/macios-mac-master/72/72334685382e27f7891ce8347b055dd45947cf3f/xamarin.mac-3.1.0.35.pkg

I wrote up a quick sample showing 8 of the most common sets of TouchBar APIs that may be useful.

https://www.dropbox.com/s/xj8rpbfknpdkaeu/TouchBarExample.zip

If you don't mind being on the bleeding edge, feel free to check things out and report issues. Please just don't go release a product on top of this. :)

Posts

  • marcokmarcok USUniversity, Certified XTC Partners ✭✭

    Hi Chris, this is awesome! I would love to fiddle around with the TouchBar API and being to do so in C# would be the best.

    Sadly, your sample seems to crash immediately on start-up on my machine. It seems to crash in the WindowController in this line:
    NSApplication.SharedApplication.SetAutomaticCustomizeTouchBarMenuItemEnabled (true)

    This is part of the Application Output (full Output in the attachment):
    2016-11-16 08:41:43.374 TouchBarExample[1341:45641] Unknown class ViewController in Interface Builder file at path /Users/marcok/Desktop/TouchBarExample/TouchBarExample/bin/Debug/TouchBarExample.app/Contents/Resources/Main.storyboardc/NSWindowController-B8D-0N-5wS.nib. 2016-11-16 08:41:43.403 TouchBarExample[1341:45641] Failed to connect (TabView) outlet from (NSViewController) to (NSTabView): missing setter or instance variable 2016-11-16 08:41:43.406 TouchBarExample[1341:45641] -[NSApplication setAutomaticCustomizeTouchBarMenuItemEnabled:]: unrecognized selector sent to instance 0x610000103840

    Normally I see this kind of Failed to connect messages when the Outlets are wrong, but when looking at your Storyboard file every reference looks OK.

    This is what I'm running:

    • XCode: Version 8.1 (8B62)
    • MacOS: Sierra Version 10.12.1 (16B2555)
    • Xamarin Studio: Version 6.1.2 (build 44)
    • Xamarin.Mac: Version: 3.1.0.35
    • MacBook Pro: Retina, 15-inch, Early 2013

    Is there something I'm missing and/or should I do something different? Thanks in advance!

  • Chris,

    I was using the latest alpha (3.0.0.274) but could not create a signed sandboxed version anymore. It was just not signing the bundle. But after installing this version it works again immediately. So there must be something wrong with latest alpha.

    The problem is we already have an app on the mac app store build from the alpha channel version 3.0.0.12 that needs to be updated.

    I cannot find any way to downgrade to 3.0.0.12 and using this non QAed version seem a like bad idea.

    Is there some way to get 3.0.0.12?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    @marcok

    2016-11-16 08:41:43.406 TouchBarExample[1341:45641] -[NSApplication setAutomaticCustomizeTouchBarMenuItemEnabled:]: unrecognized selector sent to instance 0x610000103840

    This strongly suggests that you do not have the correct macOS version. I'm running 10.12.2 (16C32f).

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    @SjoerdvanNoort https://dl.xamarin.com/XamarinforMac/Mac/xamarin.mac-3.0.0.12.pkg

    Feel free to open a separate forum post for your sand boxing issue.

  • JohnHJohnH GBMember ✭✭✭✭✭

    I know this thread is about the API's, but what are the chances of Xamarin Studio itself utilizing it?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    @JohnHair - I don't happen to have any details, since XS is a different team, and they haven't posted anything publicly. It would not surprise me too much if they are considering it though.

    As always if you have XS feedback consider posting it on their user voice:

    https://xamarin.uservoice.com/forums/144858-xamarin-platform-suggestions/category/85410-xamarin-studio

  • RogisterAlainRogisterAlain BEBeta ✭✭✭

    an you tell me if the example you give here works on a MacBook without TouchBar.

    Is it possible to have a simulator for the touchbar or should one absolutely have a macbook pro with touchbar?

    Thank you

    Alain

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    If you launch Xcode and do:

    Window -> Show TouchBar

    it will launch simulator that you can use with any application, including Xamarin.Mac ones.

  • RogisterAlainRogisterAlain BEBeta ✭✭✭

    Great ! Thanks

  • RogisterAlainRogisterAlain BEBeta ✭✭✭

    Hi,

    I have a problem with the touchbar. I would like to add a scrollview with several buttons inside but when I execute the code below, nothing appears in the touchbar. Can you help me ?

    Thank you

    Alain

    public override NSTouchBarItem MakeItem (NSTouchBar touchBar, string identifier)
    {
    NSCustomTouchBarItem item = new NSCustomTouchBarItem (identifier);

            switch (ParseId (identifier))
            {
    
    
                case 0: {
    
                    NSScrollView scrool = new NSScrollView(new CGRect(0,0,150,30));
    
                    NSButton bt = new NSButton();
    
                    bt.Image = NSImage.ImageNamed (NSImageName.TouchBarSearchTemplate);
                    bt.BezelColor = NSColor.Control;
                    bt.BezelStyle = NSBezelStyle.Rounded;
    
                    bt.Bordered = true;
    
                    bt.Activated += delegate {
    
    
                        GlobalClass.vueConsultation.AffichageRecherche();
    
    
                    };
    
                    scrool.AddSubview(bt);
    
                    bt = new NSButton();
    
                    bt.Title = "eID";
                    bt.Font = NSFont.FromFontName("Arial",14);
                    bt.BezelColor = NSColor.Control;
                    bt.BezelStyle = NSBezelStyle.Rounded;
    
                    bt.Bordered = true;
    
                    bt.Activated += delegate {
    
    
                        GlobalClass.vueConsultation.AffichageEID();
    
    
                    };
    
                    scrool.AddSubview(bt);
    
                    item.View = scrool;
    
                    return item;
                }
    
    
    
    
            }
            return null;
        }
    
  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    None of the samples here:

    https://github.com/xamarin/mac-samples/tree/master/TouchBarExample/TouchBarExample

    use NSScrollView.

    But the docs here suggest it should work:

    https://developer.apple.com/reference/appkit/nstouchbar?language=objc

    And there is a large Apple Sample here:

    https://developer.apple.com/library/content/samplecode/NSTouchBarCatalog/Listings/Objective_C_NSTouchBar_Catalog_TestViewControllers_ScrollViewController_ScrollViewController_m.html

    But I see at least one issue with your code just glancing at it.

    Do not do:

                NSButton bt = new NSButton();
    

    Do:

        var bt = NSButton.CreateButton (STUFF)
    

    Because CreateButton is smart enough to get the touchbar styling right according to the docs.

    I would start by ripping out all of the code but two buttons, and get them to show up, then add more.

  • RogisterAlainRogisterAlain BEBeta ✭✭✭

    Hi,

    I integrate the touchbar in my application and it only works but I have a problem.

    When I open a modal window, the touchbar appears correctly. When inside this modal window, I display a SheetWindow, can not display the touchbar ?

    Is this a bug?

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    @RogisterAlain I have a hard time believing this is a bug in Xamarin.Mac. Maybe it has something to do with nested message pumps or a limitation in Cocoa.

    In any case, please open another topic if you wish to discuss this. It has nothing to do with this old preview thread.

Sign In or Register to comment.