Jug*_*teR 3 plugins lifetime cordova
有没有什么我需要考虑插件实例的生命周期,或者我可以假设这个对象一直存在我的Web视图可见?
从一些插件来看,有些人倾向于使用某种单例管理器将数据存储在他们的PhoneGap插件中.为什么不将它存储在PhoneGap插件本身?
问的原因是,似乎与Web视图进行通信的唯一正确方法是通过[self writeJavaScript:message]方法.如果我注册自己收到一些通知,我想确保我的插件实例存在.
只要Web视图处于活动状态,插件就会存在.
初始化变量或注册回调的正确方法是在
- (CDVPlugin*) initWithWebView:(UIWebView*)theWebView {
self = [super initWithWebView:theWebView];
if (self) {
_variable = [[Variable alloc] init];
[Classname addListener:self];
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
方法.该方法适用于所有插件.
不要忘记在dealloc方法中自己清理.
| 归档时间: |
|
| 查看次数: |
1328 次 |
| 最近记录: |