Normally to test your fix you'd need to make the change in your IDE, and re-build and re-upload the app to your device using Xcode. This can take ages if your app has a lot of content.
If you're using Phonegap build, it can take even longer as you'll have to wait for the whole app to build and then download again. This can be particularly painful if your one line change takes a few goes to get right (especially anything UI or animation-related).
So what's the solution? Well, it's actually possible to connect your iPhone to your Mac, edit your JS file (or any other file) and re-save, and run the app again.
I was surprised to discover that this is possible - I'd assumed the code signing verification system built into the iDevice would notice that the bundle had changed and refuse to run but it doesn't. At least not in my experience.
Here's how to do it (note commercial software required, though the demo does actually work. I don't work for them and am not paid!)
- Download iExplorer 3 from here
- Connect your device
- Open the Apps folder and find your app.
- Right-click the app and choose 'Mount as Disk'
- A new drive will appear. Open it.
- Inside you'll see a bundle, e.g. com.example.myapp.
- Right-click the bundle and choose 'view package contents'
- Open the www folder (or whichever folder your app uses for PhoneGap content)
- Open the JS file you want to change in your favourite text editor (we use Sublime Text 2.app)
- Save changes. This writes it straight back to the device!
The above instructions are for Mac, but I suspect pretty much the same process will work for PC too.
Now you can re-start your app and the new code should be live!
Dealing with Cacheing issues
Note that quite regularly you'll find the iDevice still runs the old version of your JS file. This is due to the UIWebView caching the JS file.
Change the link from (for example)
Each time you change the myfile.js, also update the _cache=123 number and you'll always get the latest version. _cache doesn't actually mean anything, you can choose whatever you want.