{"_id":"57e2339d18164d0e00621410","parentDoc":null,"project":"54861bb654b3ce0b00367292","user":"548d74b716fc980b00e2a786","category":{"_id":"57df9df05927cb0e002bce1e","project":"54861bb654b3ce0b00367292","version":"57b96d6b1d08500e00bf81d1","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-09-19T08:12:32.921Z","from_sync":false,"order":7,"slug":"cordova-app-triggers","title":"Cordova / App triggers"},"__v":0,"version":{"_id":"57b96d6b1d08500e00bf81d1","__v":7,"project":"54861bb654b3ce0b00367292","createdAt":"2016-08-21T08:59:23.326Z","releaseDate":"2016-08-21T08:59:23.326Z","categories":["57b96d6b1d08500e00bf81d2","57b96d6b1d08500e00bf81d3","57b96d6b1d08500e00bf81d4","57b96d6b1d08500e00bf81d5","57b96d6b1d08500e00bf81d6","57b96d6b1d08500e00bf81d7","57b96d6b1d08500e00bf81d8","57b96d6b1d08500e00bf81d9","57b96d6b1d08500e00bf81da","57b96d6b1d08500e00bf81db","57b96d6b1d08500e00bf81dc","57b97748306b9b0e001dd53f","57d12c6c1227b40e0044908a","57d51ad68191880e008bb51b","57d52b5cf350090e00fe073e","57d5468a17b492170053a3f0","57df9df05927cb0e002bce1e"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"","version_clean":"4.0.0","version":"4.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-09-21T07:15:41.043Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"settings":"","results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":7,"body":"##Get notified when all is in sync\nAfter the session has started and when it is restarted, you can be notified and continue with the app flow.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"Initial sync\",\n  \"body\": \"Interacting with cases and dynamic objects happen only after initial sync, so take into flow consideration.\"\n}\n[/block]\nYou can use the following two notifications keys for indication. \nWhile:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"EC_SessionStarted - for when session started the first time\\nEC_SessionRestarted - for when session restarted\",\n      \"language\": \"javascript\",\n      \"name\": \"JavaScript\"\n    }\n  ]\n}\n[/block]\n\nAdd the following to your `bindEvents` function:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"document.addEventListener('EC_SessionStarted', ec_started, false);\\ndocument.addEventListener('EC_SessionRestarted', ec_restarted, false);\",\n      \"language\": \"javascript\",\n      \"name\": \"JavaScript\"\n    }\n  ]\n}\n[/block]\nFollowed by function definition for each notification:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"function ec_started(param){\\n  // indicate session started successfully \\n  var success = param.detail;\\n}\\n\\nfunction ec_restarted(param){\\n\\t// indicate session restarted successfully \\n  var success = param.detail;\\n}\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"handlers-notifications-1","type":"basic","title":"Handlers & Notifications"}

Handlers & Notifications


##Get notified when all is in sync After the session has started and when it is restarted, you can be notified and continue with the app flow. [block:callout] { "type": "warning", "title": "Initial sync", "body": "Interacting with cases and dynamic objects happen only after initial sync, so take into flow consideration." } [/block] You can use the following two notifications keys for indication. While: [block:code] { "codes": [ { "code": "EC_SessionStarted - for when session started the first time\nEC_SessionRestarted - for when session restarted", "language": "javascript", "name": "JavaScript" } ] } [/block] Add the following to your `bindEvents` function: [block:code] { "codes": [ { "code": "document.addEventListener('EC_SessionStarted', ec_started, false);\ndocument.addEventListener('EC_SessionRestarted', ec_restarted, false);", "language": "javascript", "name": "JavaScript" } ] } [/block] Followed by function definition for each notification: [block:code] { "codes": [ { "code": "function ec_started(param){\n // indicate session started successfully \n var success = param.detail;\n}\n\nfunction ec_restarted(param){\n\t// indicate session restarted successfully \n var success = param.detail;\n}", "language": "javascript" } ] } [/block]