Overriding UIViewController methods from .mm extension

105 views Asked by At

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?

1

There are 1 answers

7
Rob Napier On

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.)