2 Replies
      Latest reply on Jan 13, 2020 1:01 AM by Honghao
      pabugeater Level 1 Level 1 (0 points)

        My Catalyst App was rejected because it does not "look nice" in Mac's full screen mode.  And that is true, it's designed as a windowed App.  My first thought is to disable the green zoom button, but AFAIK I need a pointer to the NSWindow object to do that, and that's not available.

         

        Any suggestions on what to do here?  I do not mind if the green button toggles the App between its max size and the last user chosen size, say, but it's not proper for the App to enter full screen mode.

         

        Thanks,

        • Re: Disable NSWindow zoom button
          CrunchyBagel Level 1 Level 1 (5 points)

          I had the same rejection. I was subsequently able to alter the zoom functionality (or disable the green maximise button, depending on what you want to do).

           

          I haven't submitted this yet, so can't vouch for it passing app review, but here is my solution:

           

          1. Create a new target for your app. macOS -> Bundle. Use Objective C. Call it something like HelperBundle

           

          2. In your main target, go to General tab, add the new bundle under "Frameworks, Libraries and Embedded Contact"

           

          3. In your bundle, create a single class, say HelperApp:

           

          HelperApp.h:

           

          #import <Foundation/Foundation.h>
          #import <AppKit/AppKit.h>
          
          NS_ASSUME_NONNULL_BEGIN
          
          @interface HelperApp : NSObject
          
          + (void) disableMaximiseButton;
          
          @end
          
          NS_ASSUME_NONNULL_END

           

          HelperApp.m:

           

          #import "HelperApp.h"
          
          @implementation HelperApp
          
          + (void) disableMaximiseButton
          {
              for (NSWindow *window in [[NSApplication sharedApplication] windows]) {
                 
                  [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary|NSWindowCollectionBehaviorFullScreenNone|NSWindowCollectionBehaviorFullScreenDisallowsTiling];
                 
                  NSButton *button = [window standardWindowButton:NSWindowZoomButton];
                  [button setEnabled: NO];
              }
          }
          
          @end

          4. Now you need to call it from your main app. I made a method something like this. Sorry it’s in Obj-C:

           

          #if TARGET_OS_MACCATALYST
          - (void) catalystDisableMaximiseButton
          {
              NSString *bundlePath = [NSBundle.mainBundle.builtInPlugInsPath stringByAppendingString:@"/HelperBundle.bundle"];
              NSBundle *bundle = [[NSBundle alloc] initWithPath:bundlePath];
              [bundle load];
          
              NSObject *object = (NSObject *) NSClassFromString(@"HelperApp");
              [object performSelector:NSSelectorFromString(@"disableMaximiseButton")];
          }
          #endif

           

          5. Now I call it. I could only get it working by calling catalystDisableMaximiseButton in the main view controller’s “viewDidAppear” method

            • Re: Disable NSWindow zoom button
              Honghao Level 1 Level 1 (0 points)

              Awesome solution! I was able to make the zoom button disable with your solution.

               

              This is my Swift version:

               

              I created a MacHelperBundle, created a Helper.swift:

              import AppKit
              
              public class Helper {
                /// Disable the zoom button for window.
                /// - Parameter window: The window to disable.
                @objc static func disableZoomButton(for window: NSWindow) {
                  window.standardWindowButton(.zoomButton)?.isEnabled = false
                }
              }
              

               

              In the app target

                func scene(_: UIScene, willConnectTo _: UISceneSession, options _: UIScene.ConnectionOptions) {
                  #if targetEnvironment(macCatalyst)
              
                  // ...
              
                  DispatchQueue.main.async { [weak self] in
                    guard let builtInPlugInsPath = Bundle.main.builtInPlugInsPath else {
                      return
                    }
                    let bundlePath = builtInPlugInsPath + "/MacHelperBundle.bundle"
                    guard let bundle = Bundle(path: bundlePath) else {
                      return
                    }
                    bundle.load()
              
                    guard let window = self?.window?.nsWindow else {
                      return
                    }
              
                    let macHelper = bundle.classNamed("MacHelperBundle.Helper") as AnyObject
                    _ = macHelper.perform(NSSelectorFromString("disableZoomButtonFor:"), with: window)
                  }
              
                  #endif
              
                  // ...
                }
              
              extension UIWindow {
              
                /// Get the NSWindow from self.
                var nsWindow: AnyObject? {
                  guard let nsWindows = NSClassFromString("NSApplication")?.value(forKeyPath: "sharedApplication.windows") as? [AnyObject] else { return nil }
                  for nsWindow in nsWindows {
                      let uiWindows = nsWindow.value(forKeyPath: "uiWindows") as? [UIWindow] ?? []
                      if uiWindows.contains(self) { return nsWindow }
                  }
                  return nil
                }
              }