Friday, December 19, 2014

How to debug cordova onDeviceReady event

After loading the html page, the cordova will immediately call onDeviceReady event handle, so it is hard to set break pointer to debug the logic in onDeviceReady event.
One option is use javascript setInterval method, so it will hold the javascript until you change the bWait flag from javascript console window

The sample code looks like


  var onDeviceReady = function() {
        var originThis = this;
        var bWait = true;
        var bDone =false;
        var i = 0
        var timer = setInterval(
                function(){
                    if (bWait && i < 10 ){
                        i++;
                        console.log("set bWait to false from console window to continue");
                    }
                    else{
                        if (!bDone){
                            bDone = true;
                            clearInterval(timer);
                            yourOriginalOnDeviceReady.apply(originThis, arguments);
                        }
                    }
                }, 3000);
    }

Actually, this can also be used in other cases for attaching javascript debugger, particularly for the js script loaded into the DOM at runtime by xhr request. Just wrap the original function with the above function should do it.

Wednesday, December 10, 2014

Find ios simulator folder on mac

Option 1
1. While running the app on simulator from xcode, enter a breakpoint or just clicking the pause buttonn
2. in Xcode console window, type the below command
po NSHomeDirectory()
3. copy the path, and then from Finder, click Go->Go To Folder menu, and paste the path, it will show the simulator app bundle folder


Option 2
1. launch ios simulator, click Hardware->device->Manage Device... menu

2. in the opened xcode device screen, find the simulator item, select it, and get the identifier number

3. open Finder on mac and goto the folder of
/Users/<Your UserName>/Library/Developer/CoreSimulator/Devices

4. find the subfolder that has the same name.

5 go to data\applications folder and check the application name in each subfolder to find the you want to check