Cordova

Project to learn and experiment with Apache Cordova

Running

  1. Clone this repo
  2. Run the following
$ cd cordova-playground
$ cordova prepare
$ cordova build ios
$ cordova emulate ios

Leveraging JSforce

To ensure the salesforce JSforce javascript library can make https://*.salesforce.com requests from file:///.

  1. The following must be added to config.xml
  <access origin="*" />
  1. For iOS 9 and above, apple introduced App Transport Security. It can be fixed by adding the following to Info.plist
<key>NSAppTransportSecurity</key>  
<dict>  
    <key>NSAllowsArbitraryLoads</key>
    <true />  
</dict>
  1. Add www/js/jsforce.js and add a <script> for it in www/index.html.

  2. Needed to comment out the following in index.html

<!--
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
-->
  1. Run the following to rebuild and show in simulator
$ cordova prepare
$ cordova build ios
$ cordova emulate ios

Sample javascript used to test

var conn = new jsforce.Connection({loginUrl : 'https://test.salesforce.com'});
conn.login('brian.pfeil@merck.com.hhusd11', '<PASSWORD>', function(err, res) {
  if (err) { return console.error(err); }
  conn.query('SELECT Id, Name FROM Account limit 1', function(err, res) {
    if (err) { return console.error(err); }
    alert(JSON.stringify(res));
  });
});

Safari Web Inspector Session Screenshot

Key Files

config.xml
www/index.html
www/js/index.js

Resources