cordova-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Grieve <agri...@chromium.org>
Subject CDVPlugins and Designated Initializers
Date Thu, 14 Feb 2013 18:09:31 GMT
The iOS plugin guide doesn't mention init methods for plugins. We should
fix this...

But first, how...

Right now we have:

- (CDVPlugin*)initWithWebView:(UIWebView*)theWebView
> settings:(NSDictionary*)classSettings
> {
>     self = [self initWithWebView:theWebView];
>     if (self) {
>         self.settings = classSettings;
>         self.hasPendingOperation = NO;
>     }
>     return self;
> }
> - (CDVPlugin*)initWithWebView:(UIWebView*)theWebView
> {
>     self = [super init];
>     ...


So... Looks like initWithWebView: is the designated initializer, but the
plugin doesn't get it's settings set until after it returns. Also,
self.viewController and self.commandDelegate get set after the initializer
altogether.

In Android, we use two-step initialization:

                this.plugin = (CordovaPlugin) c.newInstance();
>                 this.plugin.initialize(ctx, webView);

We can't remove either initializer without breaking compatibility, but
maybe we could deprecate them?

I think it also makes sense to use two-phase initialization on iOS. Perhaps
"pluginDidInitialize".

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message