ios-jsc icon indicating copy to clipboard operation
ios-jsc copied to clipboard

Add and remove UIApplicationDelegate in runtime without overwriting existing iOS delegates

Open jdnichollsc opened this issue 5 years ago • 2 comments

Is your feature request related to a problem? Please describe. I'm always frustrated when I need to use iOS delegates but other plugins overwrite that behavior because oficial docs only show that example: ios.delegate = MyDelegate; => https://docs.nativescript.org/core-concepts/application-lifecycle#ios-uiapplicationdelegate

Describe the solution you'd like I would like having another way to add and remove subscriptions to the methods of the current delegate.

Describe alternatives you've considered Using alternatives like this https://github.com/hypery2k/nativescript-urlhandler/issues/24#issuecomment-510867679 but that makes working with deep linking, etc from NativeScript cumbersome, because most people who use UIApplicationDelegate don't use that strategy (A lot of plugins).

Additional context It's required because we don't have an unified API to get the initial URL of the app, etc, like this: https://reactnative.dev/docs/linking This is very important for most of the apps, using deep linking, etc.

Thanks for your help! Another plugin maker

jdnichollsc avatar Apr 09 '20 04:04 jdnichollsc

@jdnichollsc Thanks for tracking this 👍 We're looking at ways to improve the delegate extensions and overrides. In meantime have you tried doing it this way?

const CustomAppDelegate = (<any>UIResponder).extend(
    {
      // existing AppDelegate prototype first, then override below with customizations
      ...(Application.ios.delegate ? Application.ios.delegate.prototype : {}),

     applicationDidFinishLaunchingWithOptions: function(application: UIApplication, launchOptions: NSDictionary<any, any>) {
        // do customizations here

       return true;
     },
     {
        protocols: [UIApplicationDelegate]
     }
  );

Application.ios.delegate = CustomAppDelegate;

NathanWalker avatar Jun 12 '20 15:06 NathanWalker

@NathanWalker interesting, let me check! Is this example going to override methods of another plugins like applicationDidFinishLaunchingWithOptions, etc? Can we include that example from official docs?

Thanks for your help!

jdnichollsc avatar Jun 12 '20 17:06 jdnichollsc