UIWindow keyWindow changed notification

2.1k views Asked by At

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?

2

There are 2 answers

0
Mistah_Sheep On BEST ANSWER

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!

0
Manuel On

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.