0

In my iOS app, I would like to retrieve a reference to my app delegate using [[UIApplication sharedApplication] delegate], however this is returning an instance of class UABaseAppDelegateSurrogate instead of my custom UIApplicationDelegate class.

I understand that this surrogate is somehow used for receiving notifications, but do I need this? My app delegate implements all necessary methods for receiving notifications, and I would like to bypass this surrogate class so I can call methods on my custom app delegate. I don't know when this started happening, but I used to get my custom app delegate from [[UIApplication sharedApplication] delegate].

Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
Patrick Goley
  • 5,397
  • 22
  • 42

2 Answers2

1

I think it's application delegate from your framework. Take a look at main.m file, how UIApplicationMain is called? 3d parameter is application class, 4th is application delegate class. However, if you change it to your custom delegate class, you may lose framework's functionality. So you need to take a deeper look into UABaseAppDelegateSurrogate - maybe you can subclass it? Or completely get rid of it?

Petro Korienev
  • 4,007
  • 6
  • 34
  • 43
  • in main.m I am passing in my custom app delegate class, and always have been. The Urban Airship framework somehow hijacks the app delegate to use its surrogate, but this only recently started happening. I can get the original app delegate from a property on a surrogate, but I don't want to settle for this solution before understanding why – Patrick Goley Sep 30 '13 at 16:04
  • If framework sets its own appDelegate it needs to handle something. However it's bad pattern - every object can subscribe to UIApplication notifications via NSNotificationCenter. You can do same trick - after framework initialization set UIApplication's delegate to your own and have UABaseAppDelegateSurrogate as property in your appDelegate, just forward your notifications to it. But i don't think you have to bypass framework's delegate or hook something. The summary - framework works using it's appDelegate, if your code uses framework your code should respect it. – Petro Korienev Sep 30 '13 at 16:22
0

From the Urban Airship docs:

The Urban Airship library will automatically integrate with your app, so you do not need to implement any of the push-related UIApplicationDelegate protocol methods or pass notifications to the library. The library is able to do this by setting itself as the app delegate, intercepting messages and forwarding them to your original app delegate. If you would like to disable this behavior and implement the delegate callbacks in your own delegate, you can set automaticSetupEnabled to NO in either your AirshipConfig.plist file or on a UAConfig object passed to [UAirship takeOff:(UAConfig *)config];

Patrick Goley
  • 5,397
  • 22
  • 42