{"_id":"5b1f2cbdfd653400031d8d51","category":{"_id":"5b1f2cbdfd653400031d8d43","__v":35,"pages":["5b1f2cbdfd653400031d8d4a","5b1f2cbdfd653400031d8d4c","5b1f2cbdfd653400031d8d4d","5b1f2cbdfd653400031d8d4e","55e682b7de6fef23009480dc","5b1f2cbdfd653400031d8d4f","5b1f2cbdfd653400031d8d50","5b1f2cbdfd653400031d8d51","5b1f2cbdfd653400031d8d52","5b1f2cbdfd653400031d8d53","5b1f2cbdfd653400031d8d54","5b1f2cbdfd653400031d8d55","5b1f2cbdfd653400031d8d56","5b1f2cbdfd653400031d8d6a","5b1f2cbdfd653400031d8d6b","5b1f2cbdfd653400031d8d6c","5b1f2cbdfd653400031d8d6d","5b1f2cbdfd653400031d8d6e","5b1f2cbdfd653400031d8d71","5b1f2cbdfd653400031d8d72","5b1f2cbdfd653400031d8d74","561c6ca0be5fb20d00077754","5b1f2cbdfd653400031d8d79","5b1f2cbdfd653400031d8d7a","5b1f2cbdfd653400031d8d7b","5b1f2cbdfd653400031d8d7c","5b1f2cbdfd653400031d8d7d","5b1f2cbdfd653400031d8d7e","5b1f2cbdfd653400031d8d7f","56cfa5386c5d7a13005eec0f","56e73d86555c030e00a52a73","56e7460c9000b120000ffe2e","56e8c19e99c6400e003820cf","56e8c53fc88bf80e00f8bed8","56f06ff4d386ce0e008e9b21"],"project":"55e67aaa9cc7c62b00c4a1ea","version":"5b1f2cbdfd653400031d8d9f","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-09-02T04:30:13.305Z","from_sync":false,"order":1,"slug":"install-in-your-app","title":"Install in your app"},"user":"55d2bd8e2463351700f67dd7","__v":10,"parentDoc":null,"version":{"_id":"5b1f2cbdfd653400031d8d9f","project":"55e67aaa9cc7c62b00c4a1ea","__v":0,"forked_from":"55e67aab9cc7c62b00c4a1ed","createdAt":"2015-09-02T04:27:23.612Z","releaseDate":"2015-09-02T04:27:23.612Z","categories":["5b1f2cbdfd653400031d8d42","5b1f2cbdfd653400031d8d43","5b1f2cbdfd653400031d8d44","5b1f2cbdfd653400031d8d45","5b1f2cbdfd653400031d8d46","561c61b4ad272c0d00a892df","586c014c0abf1d0f000d04d4","58991d2ad207df0f0002186b","5b1f2cbdfd653400031d8d47","5b1f2cbdfd653400031d8d48","5af0fe494ca2730003cbc98a","5af0fe55ec80af0003804ca2"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"rebrand","version_clean":"1.3.0","version":"1.3"},"project":"55e67aaa9cc7c62b00c4a1ea","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-09-07T00:14:37.434Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":true,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":9,"body":"Sailthru Mobile supports a [Cordova](https://cordova.apache.org/) plugin that allows you to use the Sailthru Mobile SDK for iOS and Android through a JavaScript interface.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Cordova minimum version\",\n  \"body\": \"Sailthru Mobile supports the following plugins:\\n* `carnival-cli` version 6.5.0 or later\\n* `cordova-platform-ios` version 4.1.1 or later\\n* `cordova-platform-android` version 6.0.0 or later\\n\\nAlthough Sailthru Mobile may compile on with earlier versions, it may lead to unforeseen issues.\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installation\"\n}\n[/block]\nThis guide assumes Cordova is installed in your machine and your project is already initialized.\n\n## Add the plugin\nType the following command inside your project directory:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"cordova plugin add https://github.com/carnivalmobile/carnival-sdk-cordova.git\",\n      \"language\": \"shell\"\n    }\n  ]\n}\n[/block]\n\n## Add the SDK Key\n\nAdd a preference to your `config.xml` file with your Sailthru Mobile App key (from [http://mobile.sailthru.com](http://mobile.sailthru.com)).\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<platform name=\\\"ios\\\">\\n    <preference name=\\\"carnival_ios_app_key\\\" value=\\\"YOUR_APP_KEY_GOES_HERE\\\" />\\n</platform>\",\n      \"language\": \"xml\",\n      \"name\": \"iOS\"\n    },\n    {\n      \"code\": \"<platform name=\\\"android\\\">\\n    <preference name=\\\"carnival_android_app_key\\\" value=\\\"YOUR_APP_KEY_GOES_HERE\\\"/>\\n</platform>\",\n      \"language\": \"xml\",\n      \"name\": \"Android\"\n    }\n  ]\n}\n[/block]\nNext, set up push notifications for [iOS](doc:push-notifications-for-ios) and [Android](doc:enable-push-notifications-for-android).\n\n## Add the initialization code\nNext, you need to start the Carnival engine when your app starts. You need to do that when Cordova fires the `deviceready` event.\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Starting the Carnival Engine in Cordova\",\n  \"body\": \"In Cordova, the underlying Carnival engine starts automatically, but we don't listen to in-app notifications until `startEngine` is called. On iOS, we don't register for push notifications until you either call `Carnival.startEngine(true)` or you trigger the push prompt.\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener('deviceready', () => {\\n  Carnival.startEngine(true);\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\nOn iOS, passing `true` to `startEngine` will also register the device for push notifications, causing iOS to show the push notification opt-in dialog. This value is ignored on Android. If you wish to register for push notifications at a later time, simply call `startEngine` with `false`, and register at a later stage using `Carnival.registerForPushNotifications`. This is useful if your app has an onboarding experience and you want to delay the push prompt until after the user lands on the pre-push stage.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener('deviceready', () => {\\n  // Start the Carnival engine, but don't register for pushes yet\\n  Carnival.startEngine(false);\\n});\\n\\n// At a later stage, trigger the push prompt\\nCarnival.registerForPushNotifications();\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"Integration instructions for Cordova Apps","slug":"cordova-integration","type":"basic","title":"Cordova Integration"}

Cordova Integration

Integration instructions for Cordova Apps

Sailthru Mobile supports a [Cordova](https://cordova.apache.org/) plugin that allows you to use the Sailthru Mobile SDK for iOS and Android through a JavaScript interface. [block:callout] { "type": "info", "title": "Cordova minimum version", "body": "Sailthru Mobile supports the following plugins:\n* `carnival-cli` version 6.5.0 or later\n* `cordova-platform-ios` version 4.1.1 or later\n* `cordova-platform-android` version 6.0.0 or later\n\nAlthough Sailthru Mobile may compile on with earlier versions, it may lead to unforeseen issues." } [/block] [block:api-header] { "type": "basic", "title": "Installation" } [/block] This guide assumes Cordova is installed in your machine and your project is already initialized. ## Add the plugin Type the following command inside your project directory: [block:code] { "codes": [ { "code": "cordova plugin add https://github.com/carnivalmobile/carnival-sdk-cordova.git", "language": "shell" } ] } [/block] ## Add the SDK Key Add a preference to your `config.xml` file with your Sailthru Mobile App key (from [http://mobile.sailthru.com](http://mobile.sailthru.com)). [block:code] { "codes": [ { "code": "<platform name=\"ios\">\n <preference name=\"carnival_ios_app_key\" value=\"YOUR_APP_KEY_GOES_HERE\" />\n</platform>", "language": "xml", "name": "iOS" }, { "code": "<platform name=\"android\">\n <preference name=\"carnival_android_app_key\" value=\"YOUR_APP_KEY_GOES_HERE\"/>\n</platform>", "language": "xml", "name": "Android" } ] } [/block] Next, set up push notifications for [iOS](doc:push-notifications-for-ios) and [Android](doc:enable-push-notifications-for-android). ## Add the initialization code Next, you need to start the Carnival engine when your app starts. You need to do that when Cordova fires the `deviceready` event. [block:callout] { "type": "info", "title": "Starting the Carnival Engine in Cordova", "body": "In Cordova, the underlying Carnival engine starts automatically, but we don't listen to in-app notifications until `startEngine` is called. On iOS, we don't register for push notifications until you either call `Carnival.startEngine(true)` or you trigger the push prompt." } [/block] [block:code] { "codes": [ { "code": "document.addEventListener('deviceready', () => {\n Carnival.startEngine(true);\n});", "language": "javascript" } ] } [/block] On iOS, passing `true` to `startEngine` will also register the device for push notifications, causing iOS to show the push notification opt-in dialog. This value is ignored on Android. If you wish to register for push notifications at a later time, simply call `startEngine` with `false`, and register at a later stage using `Carnival.registerForPushNotifications`. This is useful if your app has an onboarding experience and you want to delay the push prompt until after the user lands on the pre-push stage. [block:code] { "codes": [ { "code": "document.addEventListener('deviceready', () => {\n // Start the Carnival engine, but don't register for pushes yet\n Carnival.startEngine(false);\n});\n\n// At a later stage, trigger the push prompt\nCarnival.registerForPushNotifications();", "language": "javascript" } ] } [/block]