iOS 9, Cordova, and jQuery mobile apps Integration tips

Unfortunately after having iOS 9 update, you may find your Cordova jQuery mobile app has the following problems:

  1. All of your app’s popups are suddenly closed after the first opening time!
  2. All your app’s back button are not working anymore!

The root cause of these problems is a bug in iOS9 UIWebView‘s window.location.hash as shown in the link below:


In order to fix these issues, you can do the following workarounds.

Fixing the sudden closing pop-up

In order to fix this issue, make sure to set the data-history attribute of jQuery mobile popup to "false". An example of this is shown in the link below:

Fixing the broken back button

In order to fix this issue, make sure to disable the hash listening behaviour for jQuery mobile when the device is ready. You need to be careful when applying this fix, make sure that this fix will be applied for only iOS version 9 as shown in the code snippet below.

if (device.platform === "iOS"  && parseInt(device.version) === 9) {
} /* when the device is ready */

Checking a working Cordova jQuery mobile app in iOS 9

Finally, you can check a complete working Cordova jQuery mobile app in iOS 9. This app is one of the examples of the “JavaScript Mobile Application Development” book which can be reached at:

The example app uses Apache Cordova 5.3.3 and jQM 1.4.5. Enjoy!

Tip #4: Storing Media Files Properly in Cordova iOS apps

In order to avoid being surprised by the loss of your recorded audio file in iOS, you should be aware of how to properly record and store a media file in Cordova iOS.
Generally, in order to record an audio file in Apache Cordova, you can use the Cordova Media object as follows:

var recordingMedia = new Media(mediaFilePath, recordingSuccess, recordingError);

// Start Recording Audio

// Stop Recording Audio

// Release Media resource

As shown in the code above, in order to record an audio file in Apache Cordova, you need to do the following:

  1. Create a Media object (recordingMedia) and specify mediaFilePath (the path of the audio file), recordingSuccess (the success callback which will be called if the media operation succeeds), recordingError (the error callback which will be called if the media operation fails).
  2. Start recording the audio by calling recordingMedia.startRecord().
  3. After completing the audio recording, call recordingMedia.stopRecord() and then release the used Media object by calling recordingMedia.release()

In iOS, if you set mediaFilePath to the audio file name only without specifying any path (e.g "test.wav"), you may be surprised to find your audio file stored under the iOS app’s tmp directory (which is located under the iOS app’s sandbox directory). It is very important to be aware that the iOS app’s tmp directory content can be deleted automatically by iOS at anytime by iOS.

In order to avoid losing your app’s recorded files, just place the "documents://" prefix before the audio file name as follows.

var recordingMedia = new Media("documents://test.wav", recordingSuccess, recordingError);

Doing this will make the recorded audio file stored under the iOS app’s Documents directory. The iOS app’s Documents directory is located under the app’s sandbox directory and is suitable for storing the app files.


“JavaScript Mobile Application Development” Book:

Sharing Xcode 5 projects on SVN with no issues

In order to share Xcode 5 project on SVN, you can do it by doing the following:
1. Choose Xcode -> Preferences.
2. Choose “Accounts” tab.
3. In the “Accounts” tab, click “+” -> “Add Repository”.
4. Enter the SVN Repository information as shown in the screenshot below:
SVN Information Window

P.S. You may face the following error while trying to add SVN repo to Xcode as follows:
xcode cannot verify the identity of the server

In order to resolve this issue, just click "Show Certificate", unfold the disclosure arrow and set the “Trust” option menu to “Always Trust”.

5. After doing these steps, you can choose the local folder ("iOSProjects" for example) in which you want to do svn checkout. You can do this from "Source code" -> "Checkout".

6. Finally, you can create (or place) your Xcode project under your local folder "iOSProjects" to add and commit the project files to SVN.