문제

Is there something I need to take into account about the plugin instance lifetime, or can I assume that this object exists all the time my web view is visible?

It seems from looking at a few plugins, some people tend to use some kind of singleton manager to store data in their PhoneGap plugins. Why not just store it in the PhoneGap plugin itself?

The reason for asking is that it seems the only proper way to communicate with the web view is through the [self writeJavaScript:message] method. If I register myself to receive some notification, I want to be sure my plugin instance exist.

도움이 되었습니까?

해결책

The plugin lives as long as the web view is alive.

The proper way to initialize variables or register for callbacks is in the

- (CDVPlugin*) initWithWebView:(UIWebView*)theWebView {
   self = [super initWithWebView:theWebView];
   if (self) {
       _variable = [[Variable alloc] init]; 
       [Classname addListener:self];
   }
   return self;
}

method. That method is run for all plugins.

Don't forget to clean up after yourself in the dealloc method.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top