To provide the correct version of Javascript libraries, create a separate bundle for each Salesforce Mobile SDK version you use. Then, provide Apex code on the server that downloads the required version.
-
For each Salesforce Mobile SDK version that your application supports, do the following.
-
Create a ZIP file containing the Javascript libraries from the intended SDK version.
-
Upload the ZIP file to your org as a static resource.
For example, if you ship a client that uses Salesforce Mobile SDK v. 1.3, add these files to your ZIP file:
cordova.force.jsSalesforceOAuthPlugin.jsbootconfig.jscordova-1.8.1.js, which you should rename ascordova.js
note: In your bundle, it’s permissible to rename the Cordova Javascript library as
cordova.js(orPhoneGap.jsif you’re packaging a version that uses aPhoneGap-*x.x*.jslibrary.) -
-
Create an Apex controller that determines which bundle to use. In your controller code, parse the user agent string to find which version the client is using.
-
In your org, from Setup, click Develop | Apex Class.
-
Create a new Apex controller named
SDKLibControllerwith the following definition.public class SDKLibController { public String getSDKLib() { String userAgent = ApexPages.currentPage(). getHeaders().get('User-Agent'); if (userAgent.contains('SalesforceMobileSDK/1.3')) { return 'sdklib13'; } // Add if statements for other SalesforceSDK versions // for which you provide library bundles. } }
-
-
Create a Visualforce page for each library in the bundle, and use that page to redirect the client to that library.
For example, for the SalesforceOAuthPlugin library:
-
In your org, from Setup, enter
Visualforce Pagesin the Quick Find box, then select Visualforce Pages. -
Create a new page called “SalesforceOAuthPlugin” with the following definition.
<apex:page controller="SDKLibController" action="{!URLFor($Resource[SDKLib], 'SalesforceOAuthPlugin.js')}"> </apex:page> -
Reference the VisualForce page in a
<script>tag in your HTML code. Be sure to point to the page you created in step 3b. For example:<script type="text/javascript" src="/apex/SalesforceOAuthPlugin" />note: Provide a separate
<script>tag for each library in your bundle.
-