0

what im trying to accomplish is on pressing the statusbar a alert pops up. im trying to learn tweak development and the tutorial im following is a bit old and uses the deprecated UIAlertView So after finding the correct header (UIAlertController) i get the following errors trying to compile the tweak. Sry if this is a noob question i googled and nowhere really gave a clear answer for it. thanks in advance.

code-

#include <UIKit/UIKit.h>

%hook SBStatusBarManager

-(void)handleStatusBarTapWithEvent:(id)arg1{

UIAlertController *alert = [[UIAlertController alloc] alertControllerWithTitle:@"My Alert" message:@"I hope this works!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];

[alert addAction:defaultAction];
[self presentViewController:alert animated:YES completion:nil];

%orig;

}

%end

Here are the errors i got trying to compile.

  • Tweak.x:9:55: error: no visible @interface for 'UIAlertController' declares the selector 'alertControllerWithTitle:message:preferredStyle:'
  • Tweak.x:13:7: error: no visible @interface for 'SBStatusBarManager' declares the selector 'presentViewController:animated:completion:'

1 Answers1

0

Firstly:

alertControllerWithTitle:message:preferredStyle is a class method, so you cannot call it on an instance.

This should work:

UIAlertController* alertController = [UIAlertController alertControllerWithTitle:@"My Alert"
                                                                         message:@"I hope this works!"
                                                                  preferredStyle:UIAlertControllerStyleAlert]

Secondly:

SBStatusBarManager is not a UIViewController, so you need to find a suitable UIViewController that can present your alert controller.

Maybe you can try to access the root view controller, this link should help: https://stackoverflow.com/a/36879892/3227743

Then, you can present the alert view controller accordingly.

EDUsta
  • 1,932
  • 2
  • 21
  • 30