1

I'm creating a jailbreak tweak that adds a view to the UIWindow of whatever the current keyWindow is. The problem is that whenever the keyWindow changes the view gets removed.

I'm using this

%hook SBApplication
-(void)willActivate {
    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0,320,53)];
    view.backgroundColor = [UIColor greenColor];
    [window addSubview:view];
}
%end

is there another method that is better to use here or is there a notification that is sent whenever the window changes?

Mistah_Sheep
  • 785
  • 6
  • 25

2 Answers2

2

Yes, there is a notification you can observe:

UIWindowDidBecomeKey

Posted whenever a UIWindow object becomes the key window. The notification object is the window object that has become key. This notification does not contain a userInfo dictionary.

More in the docs.

Manuel
  • 14,274
  • 6
  • 57
  • 130
1

Figured it out!

Method called when a keyWindow is changed is in UIWindow and the method is

-(void)makeKeyWindow

just hook that and then add your subview!

Mistah_Sheep
  • 785
  • 6
  • 25