Guys Guys - 1 year ago 116
Objective-C Question

Getting the current active UIWindow/appDelegate object without holding the apps objects

I'm writing a "blackbox" library. In this library I need to add a subView to any app which uses my library.

Therefore, I don't have any reference to the appDelegate nor to the UIWindow of the application.

The only thing the external app is doing now is the following :

myRec = [[Rec alloc] init];
myRec.delegate = self;
[myRec start];

where Rec is the blackbox library and myRec is the instance that's used by an external app.

Of course, I can't get any reference to the view of the app through the delegate member cause it's not defined like the specific type of the external app.

Any ideas on how to get a grasp on the UIWindow object / appDelegate object without knowing their identity in advance ??

Thanks !!

Answer Source

Getting the App Delegate:

id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];

Getting the UIWindow object:

UIWindow* window = [[UIApplication sharedApplication] keyWindow];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download