Cordova iOS自定义插件:处理内存警告 [英] Cordova iOS custom Plugin : handle memory warning

查看:711
本文介绍了Cordova iOS自定义插件:处理内存警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用cordova(2.1)和一些自定义插件的iOS应用程序。

I'm developing an iOS app that use cordova(2.1), and some custom plugins.

我想要面对的问题如下:
当我显示我的插件(基本上是一个相机插件比内置的
cordova插件更多的功能)有时我收到一个内存警告和随之而来的卸载包含webview的
视图。这对我来说真是一个很大的问题,因为一旦我的imagePicker
被关闭,webview就无法恢复了。

The problem that I'm trying to face is the following : When I show my plugin(basically a camera plugin with more features than the built-in cordova plugin) sometime I receive a memory warning and a consequent unload of the view containing the webview. This is a really huge issue for me because once my imagePicker is dismissed the webview is not restored.

我看了一下CDVCamera插件源码我注意到这是:

I had a look at the CDVCamera plugin source and what I noted is this :

(1)插件保存webview:

(1) the plugin save the webview :

 // we need to capture this state for memory warnings that dealloc this object
    cameraPicker.webView = self.webView;

这里我不明白发生了什么,确定我们保存webview, b $ b警告它将被卸载,但我不能弄清楚如何/在框架中的webview
恢复。

here I don't understand what's going on, ok we save the webview in case after a memory warning it will be unloaded, but I can't figure it out how/where in the framework the webview is restored.

(2)插件使用一个名为hasPendingOperation的Bool属性,如果我理解
是由CDVViewController使用的,当收到内存警告时,如果插件是活动的,则避免清除内存

(2) The plugin use a Bool property called hasPendingOperation, this property If I understood is used by the CDVViewController when a memory warning is received to avoid purging the memory if a plugin is active.

我不明白的第一件事是下面为什么当我的控制器收到内存警告
超级控制器(CDVViecontroller)没有收到它?

The first things that I don't understand is the following why when my controller receive a memory warning the supercontroller(CDVViecontroller) don't receive it?

其次,是否可以将CDVCamera插件使用的模式与CDVViewController
结合使用,以处理自定义插件中的内存警告?

Second is it possible to apply the pattern used by the CDVCamera plugin in conjunction with the CDVViewController to handle memory warnings in custom plugins?

任何有助于使用cordova管理内存警告,以避免webview被卸载。

Any helps in manage memory warnings with cordova to avoid the webview to be unloaded will be appreciated.

推荐答案


  1. 这可能是一个遗留的用途,我们需要保持一个引用webView来写入javascript,当选择器被关闭。不是真的需要,因为我们使用不同的方式写回到webview: https://github.com/apache/cordova-ios/blob/0a978a6617c58bfa98968e0c6bdcdb4f10f01902/CordovaLib/Classes/CDVCamera.m#L301

不确定你的意思,CDVViewController也收到内存警告,并查询每个插件的hasPendingOperation属性。如果它设置为true,插件不会释放。注意,如果内存不足,iOS看门狗可能会杀死应用程序。

Not sure what you mean, the CDVViewController does receive the memory warning as well, and queries each plugin's hasPendingOperation property. If it is set to true, the plugin is not deallocated. Note that the iOS watchdog may kill the app anyway if memory is not sufficiently released.

这篇关于Cordova iOS自定义插件:处理内存警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆