1

I'm trying to make an extension for Game Maker : Studio that disables Notification bar when dragging from the top of the screen.

The extension is a combination of .mm and .h files.

I'd like to use the solution described in this post, but I'm unfamiliar with Objective C++ and unsure about the scope/usage of the methods referenced there.

NotificationBar.h:

@interface NotificationBar : NSObject
{
}
@end

NotificationBar.mm:

#include <UIKit/UIKit.h>

@implementation NotificationBar
- (void)viewDidLoad {
    [super viewDidLoad];

    if (@available(iOS 11.0, *)) { 
      [self setNeedsUpdateOfScreenEdgesDeferringSystemGestures];
    }
 }

- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures
{
    return UIRectEdgeAll;
}
@end

This code gives an error 'NotificationBar' cannot use 'super' because it is a root class. Is there a way to override these methods from an .mm extension?

  • You may want to [edit] your question and add declaration details (the content of your header file), otherwise it's unclear what the `NotificationBar` implementation refers to. If you actually extend an existing class, you should not trying to shadow its own methods by declaring methods with the same name. – The Dreams Wind Jul 05 '23 at 21:36
  • Thank you, included the .h file to the post. I’m not sure though what has to be added to it, do I have to declare viewDidLoad inside to be able to override it inside the .mm file? – Nick Blackwood Jul 06 '23 at 17:10

1 Answers1

2

From your code and link, it seems that you want NotificationBar to be a UIViewController. In that case you need to declare that. I believe this is the header you want:

#import <UIKit/UIKit.h>

@interface NotificationBar : UIViewController
@end

In your .mm file, you would write:

#import "NotificationBar.h"

@implementation NotificationBar

... Your existing overrides ...

... The rest of this class; otherwise this isn't going to do much ...
@end

I don't know anything about Game Maker Studio, but keep in mind that what you've written just defines a new class called NotificationBar. It doesn't extend an existing one, and if GMS already defines an ObjC class called NotificationBar it will create a conflict. If you want to extend something that GMS defines, you will need to explore how GMS permits that. There's no universal answer to it. (Someone with GMS experience may be able to help further here.)

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Thank you! Now, when I do that I get these errors: `Use of '@import' when C++ modules are disabled, consider using -fmodules and -fcxx-modules`, `Cannot find interface declaration for 'UIViewController', superclass of 'NotificationBar'` Yeah, there's no way to use Objective C/Objective C++ inside GMS, and I'm not sure how the engine compiles native code from GML (Game Maker Language) to it and where it defines its classes. – Nick Blackwood Jul 07 '23 at 13:06
  • Ah; you're not compiling with modules. You can replace `@import UIKit;` with `#import `. They're fairly similar, and you probably don't need module support for this kind of problem. – Rob Napier Jul 07 '23 at 13:46
  • It compiles now! But... it doesn't disable the Notification bar. Is there a way to find what UIViewController I need to extend for the code to work? I guess there has to be one that is created on game launch? I've asked YoYo directly (no reply yet), but I wonder if there's some conventional approach to this or a way to find out which class to extend. – Nick Blackwood Jul 09 '23 at 16:05
  • This is not extending a class. ("It doesn't extend an existing one, and if GMS already defines an ObjC class called NotificationBar it will create a conflict.") In fact, you can't extend a class this way at all in the general case. That's what I meant by "If you want to extend something that GMS defines, you will need to explore how GMS permits that." GMS has to provide you a mechanism. There's nothing about ObjC(++) that does what you're describing by default. There are absolutely ways that systems can **use** ObjC to implement what you're describing, but the framework needs to provide hooks. – Rob Napier Jul 09 '23 at 20:02
  • (This isn't strictly true. ObjC includes some very powerful tools like isa-swizzling that allow you to reach into the runtime and modify existing objects. And tools like F-ScriptAnywhere can enable it even in running programs, though I don't believe it still works on modern versions of macOS. But this is a very advanced topic, and requires intimate understanding of how this specific system is implemented. The starting point is going to be with either the GMS docs or someone very familiar with programming for it. It's not a question of ObjC.) – Rob Napier Jul 09 '23 at 20:04
  • @NickBlackwood what do you mean exactly by "disabling the notification bar"? In iOS there is no way to prevent the user from dragging the notification bar if the user wants to. You may merely hide it to introduce look and feel of a full-screen application. If this is what you are pursuing, you may want to consult answers to [this](https://stackoverflow.com/questions/24236912/how-do-i-hide-the-status-bar-in-a-swift-ios-app) question – The Dreams Wind Jul 10 '23 at 19:22
  • @TheDreamsWind I'd like to achieve same behavior as in Shovel Knight Dig - the first drag from the top brings up a little arrow and the second drag brings up the Notification Bar. Here's a preview: https://www.dropbox.com/s/471sx9epdqyfw59/RPReplay_Final1689099836.mov?dl=0 – Nick Blackwood Jul 11 '23 at 18:27