Unload Cordova Views From Stack

77 views
Skip to first unread message

Otávio Junqueira

unread,
Jun 23, 2016, 9:34:09 PM6/23/16
to phonegap
Hi guys,

In order to situate my question, i`ll try to answer all instructions described for you.

I used the tutorial 'Embedding the Webview' (http://docs.phonegap.com/develop/1-embed-webview/ios/), following 'Option 1: Combining iOS Native and WebView Components with CocoaPods'. That means:

- Developing for iOS using swift in Xcode '7.3.1'.
- Building for iOS only.
- Installed npm '2.15.1'.
- Installed cocoapods '0.39.0'.
- Added pod to existent project and defined Podfile as below:

platform :ios,                              '9.0'

# Uncomment this line if you're using Swift

use_frameworks!


# CordovaLib Dependency Pod

pod 'Cordova',                              '4.0.1'


# Cordova Core Plugin Dependency Pod References

pod 'CordovaPlugin-console',                '0.2.10'

pod 'cordova-plugin-camera',                '2.1.0'

pod 'cordova-plugin-contacts',              '2.0.1'

pod 'cordova-plugin-device',                '1.1.1'

pod 'cordova-plugin-device-orientation',    '1.0.2'

pod 'cordova-plugin-device-motion',         '1.2.0'

pod 'cordova-plugin-globalization',         '1.0.2'

pod 'cordova-plugin-geolocation',           '2.1.0'

pod 'cordova-plugin-file',                  '4.1.1'

pod 'cordova-plugin-media-capture',         '1.2.0'

pod 'cordova-plugin-network-information',   '1.2.0'

pod 'cordova-plugin-splashscreen',          '2.1.0'

pod 'cordova-plugin-inappbrowser',          '1.3.0'

pod 'cordova-plugin-file-transfer',         '1.5.0'

pod 'cordova-plugin-statusbar',             '2.1.1'

pod 'cordova-plugin-vibration',             '2.1.0'


# The following includes the PhoneGap iOS Platform Project Template for a quick start

pod 'phonegap-ios-template',                '0.2.0'



After those settings, I just changed my UIViewController class to an CDVViewController and that was enough to see the grey image http://docs.phonegap.com/images/template-run.png as expected.

Then I created a new UIViewController and add one button to this controller and one to CDVViewController created earlier. Each button received an 'action segue' leading to the other controller. 

Then i runned the app (on macos Simulator) and started to click on the buttons I created. Doing that, it kept changing between both controllers, from a view to another.

So i started Safari in order to debug the HTML code. Then I could see in 'develop' menu that there were as many 'index.html' files to debug as many times I entered on CDVViewControler.

My question would be: "Is there a way I can unload these html from memory?".

My best shot was using both views as UIViewControllers and adding a static variable for one of them. This static variable kept reference to one CDVViewController that was added to current controller as described here: https://groups.google.com/forum/#!searchin/phonegap/cdvviewcontroller/phonegap/RtF8uUTd7kM/i-kfbkkfGioJ. Doing this I partially solve the problem. But i would need to 'restart/reload' the view whenever it becomes first respondent.


Thanks in advance,

--Otávio

jcesarmobile

unread,
Jun 25, 2016, 3:04:27 PM6/25/16
to phonegap
Using segues you are probably creating new view controllers everytime you click the button. If you want to navigate to a new viewcontroller and go back consider using a navigation view controller. If you want to have 2 different view controllers that keep the status the same time, consider using a tab view controller

Otávio Junqueira

unread,
Jun 27, 2016, 4:04:03 PM6/27/16
to phonegap
Hi jcesarmobile!

In first place, i would like to thank you for your consideration trying to help me! : )

I tried to simplify my explanation with the example I gave earlier.. The point is that I am creating an app that is going to have some games embedded exported as cordova.

Let's say that I have a 'welcome screen' offering 10 games. Whenever the user chooses one of them, i need to start it from the beginning (don't need to keep any status) and whenever view resigns as first controller, i need to erase all data related to it. I'm facing some memory issues since the controllers aren't being dismissed.. 

I already tried to:

- use CDVViewControllers as the custom class of the storyboard view;
- use UIViewControllers as the custom class of the storyboard view, and embedding a CDVViewController whenever loading it;
- use just one static CDVViewController, but i can't restart it (the moment i gave it a wwwFolderName, i were not able to change it and start the game once more). If I have one static CDVViewController for each game, and starts all of them, the memory issue keeps haunting me;

I can create a small xcode project reflecting my issue if u can think u can help! : )

Bye

jcesarmobile

unread,
Jun 27, 2016, 5:50:01 PM6/27/16
to phonegap
Sure, upload the sample project

Otávio Junqueira

unread,
Aug 16, 2016, 8:47:40 PM8/16/16
to phonegap
Hello once more!

I uploaded to Github the sample project under https://github.com/ojunqueira/memorycrash. Are you still interested on helping me to find the solution?

Thanks in advance,

--Otavio

Em segunda-feira, 27 de junho de 2016 18:50:01 UTC-3, jcesarmobile escreveu:
Sure, upload the sample project

jcesarmobile

unread,
Aug 26, 2016, 3:24:24 PM8/26/16
to phonegap
The problem is what I said, you are creating new views everytime (native and cordova views) because you are not using the segues correctly.

You can create a custom segue to close the cordova modal views
http://jeffreysambells.com/2014/02/19/dismissing-a-modal-view-using-a-storyboard-segue

Or create an unwind segue
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/UsingSegues.html

Otávio Junqueira

unread,
Aug 30, 2016, 12:52:35 PM8/30/16
to phonegap
Just perfect jcesarmobile! How can I thank you?!

Took the 'dismiss view' option on the first link you sent..

jcesarmobile

unread,
Aug 30, 2016, 2:10:00 PM8/30/16
to phonegap
No need to thank me, I'm glad to help
Reply all
Reply to author
Forward
0 new messages