Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and remove UIApplicationDelegate in runtime without overwriting existing iOS delegates #1268

Open
jdnichollsc opened this issue Apr 9, 2020 · 2 comments

Comments

@jdnichollsc
Copy link

jdnichollsc commented Apr 9, 2020

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 hypery2k/nativescript-urlhandler#24 (comment) 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

@NathanWalker
Copy link
Contributor

NathanWalker commented Jun 12, 2020

@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;

@jdnichollsc
Copy link
Author

jdnichollsc commented Jun 12, 2020

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants