{"__v":8,"_id":"55bb46cca8400c2d00873dea","category":{"__v":2,"_id":"5681681330018c0d006bf7ff","pages":["5683c92f4aecbd0d00a465c2","5683e9ed72bb720d0091f64e"],"project":"559a61d2dbcfd20d00710b39","version":"559a61d2dbcfd20d00710b3c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-12-28T16:49:23.982Z","from_sync":false,"order":13,"slug":"cordova-api-reference","title":"Cordova / PhoneGap SDK Reference"},"parentDoc":null,"project":"559a61d2dbcfd20d00710b39","user":"559a618bdbcfd20d00710b38","version":{"__v":23,"_id":"559a61d2dbcfd20d00710b3c","project":"559a61d2dbcfd20d00710b39","createdAt":"2015-07-06T11:09:06.510Z","releaseDate":"2015-07-06T11:09:06.510Z","categories":["559a61d3dbcfd20d00710b3d","55a589ddaaf9cf1900114dd0","55a589e30f354f0d00fd0312","55a589ea80c8a30d00b323cc","55a589f6aaf9cf1900114dd1","55a58d4e80c8a30d00b323e6","55a8e7a227a17d21005251a2","55a93098cf45e1390093f351","55afb085f202b12100cd9e83","55afb22e902fd51700f5f8bf","55afb260902fd51700f5f8c2","55afb28ec8a85321007a5462","55afb294f202b12100cd9e95","55afb29b902fd51700f5f8c5","55afb2a1c8a85321007a5463","55afb2a7902fd51700f5f8c7","55afb2ad902fd51700f5f8c8","55afb2b5902fd51700f5f8ca","55b74b2131bccb190081bedc","55bb441b54f9640d006e6cf2","565711085cb2420d00d70071","5681681330018c0d006bf7ff","588f38b5923d610f00c72dad"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"Version 1.0","version_clean":"1.0.0","version":"1"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-31T09:58:36.554Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"###Print MOCA SDK version\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.version (function (version) {\\n      // ...\\n  });\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get MOCA app key:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n  MOCA.appKey (function (key) {\\n     // ...\\n  });\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get MOCA app secret:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n  MOCA.appSecret (function (secret) {\\n     // ...\\n  });\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Check if MOCA was initialized:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  if (MOCA.initialized(function (isInited)) {\\n      if (isInited) {\\n         // ...\\n      } else {\\n         // ...\\n      }\\n  }\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Check if MOCA proximity is enabled:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  if (MOCA.proximityEnabled(function (enabled)) {\\n      if (enabled) {\\n         // ...\\n      } else {\\n         // ...\\n      }\\n  }\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Enable MOCA proximity:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"MOCA.setProximityEnabled(true, function () {\\n\\t// ...\\n});\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get log level:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.logLevel (function (level) {\\n      // ...\\n  });   \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Set log level\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  // var level = \\\"info\\\" | \\\"debug\\\" | \\\"trace\\\" | \\\"warning\\\" | \\\"error\\\" | \\\"off\\\"\\n  MOCA.setLogLevel (level, function () {\\n      // ...\\n  });    \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Login user:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"MOCA.login (userId, function () {\\n\\t// ...\\n});      \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Logout current user:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.logout (function () {\\n      // ...\\n  });      \",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Check if user has been logged in:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.userLoggedIn (function (isLoggedIn) {\\n      if (isLoggedIn) {\\n         // ...\\n      } else {\\n         // ...\\n      }\\n  });      \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Perform asynchronous fetch of beacons/campaigns data from cloud:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCA.performFetch (function (data) {\\n      // ...\\n  });      \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get custom property by key:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n  MOCA.customProperty (key, function (key, value) {\\n      // ...\\n  });      \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n\n###Set custom property (key/value):\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n  MOCA.setCustomProperty (key, value, function () {\\n      // ...\\n  });      \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get MOCA instance unique ID:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n  MOCAInstance.identifier (function (iid) {\\n      // ...\\n  });      \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get app session number:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\n  MOCAInstance.session (function (sessionNumber) {\\n      // ...\\n  });      \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get device push token\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"  MOCAInstance.deviceToken (function (token) {\\n      // ...\\n  });      \\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]\n###Get place device is currently visiting\n\n- It returns an array with the place(s) you are currently visiting\n- Combine this call with the `addEnterPlaceListener` callback to ensure you detect places correctly.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \" MOCA.placesInside(function (e) {\\n    console.log(\\\"places inside: \\\");\\n    console.log(e);\\n});\\n\",\n      \"language\": \"javascript\"\n    }\n  ]\n}\n[/block]","excerpt":"","slug":"javascript-api-usage","type":"basic","title":"JavaScript API Usage"}

JavaScript API Usage


###Print MOCA SDK version [block:code] { "codes": [ { "code": " MOCA.version (function (version) {\n // ...\n });", "language": "javascript" } ] } [/block] ###Get MOCA app key: [block:code] { "codes": [ { "code": "\n MOCA.appKey (function (key) {\n // ...\n });\n", "language": "javascript" } ] } [/block] ###Get MOCA app secret: [block:code] { "codes": [ { "code": "\n MOCA.appSecret (function (secret) {\n // ...\n });\n", "language": "javascript" } ] } [/block] ###Check if MOCA was initialized: [block:code] { "codes": [ { "code": " if (MOCA.initialized(function (isInited)) {\n if (isInited) {\n // ...\n } else {\n // ...\n }\n }", "language": "javascript" } ] } [/block] ###Check if MOCA proximity is enabled: [block:code] { "codes": [ { "code": " if (MOCA.proximityEnabled(function (enabled)) {\n if (enabled) {\n // ...\n } else {\n // ...\n }\n }\n", "language": "javascript" } ] } [/block] ###Enable MOCA proximity: [block:code] { "codes": [ { "code": "MOCA.setProximityEnabled(true, function () {\n\t// ...\n});", "language": "javascript" } ] } [/block] ###Get log level: [block:code] { "codes": [ { "code": " MOCA.logLevel (function (level) {\n // ...\n }); ", "language": "javascript" } ] } [/block] ###Set log level [block:code] { "codes": [ { "code": " // var level = \"info\" | \"debug\" | \"trace\" | \"warning\" | \"error\" | \"off\"\n MOCA.setLogLevel (level, function () {\n // ...\n }); ", "language": "javascript" } ] } [/block] ###Login user: [block:code] { "codes": [ { "code": "MOCA.login (userId, function () {\n\t// ...\n}); ", "language": "javascript" } ] } [/block] ###Logout current user: [block:code] { "codes": [ { "code": " MOCA.logout (function () {\n // ...\n }); ", "language": "javascript" } ] } [/block] ###Check if user has been logged in: [block:code] { "codes": [ { "code": " MOCA.userLoggedIn (function (isLoggedIn) {\n if (isLoggedIn) {\n // ...\n } else {\n // ...\n }\n }); \n", "language": "javascript" } ] } [/block] ###Perform asynchronous fetch of beacons/campaigns data from cloud: [block:code] { "codes": [ { "code": " MOCA.performFetch (function (data) {\n // ...\n }); \n", "language": "javascript" } ] } [/block] ###Get custom property by key: [block:code] { "codes": [ { "code": "\n MOCA.customProperty (key, function (key, value) {\n // ...\n }); \n", "language": "javascript" } ] } [/block] ###Set custom property (key/value): [block:code] { "codes": [ { "code": "\n MOCA.setCustomProperty (key, value, function () {\n // ...\n }); \n", "language": "javascript" } ] } [/block] ###Get MOCA instance unique ID: [block:code] { "codes": [ { "code": "\n MOCAInstance.identifier (function (iid) {\n // ...\n }); \n", "language": "javascript" } ] } [/block] ###Get app session number: [block:code] { "codes": [ { "code": "\n MOCAInstance.session (function (sessionNumber) {\n // ...\n }); \n", "language": "javascript" } ] } [/block] ###Get device push token [block:code] { "codes": [ { "code": " MOCAInstance.deviceToken (function (token) {\n // ...\n }); \n", "language": "javascript" } ] } [/block] ###Get place device is currently visiting - It returns an array with the place(s) you are currently visiting - Combine this call with the `addEnterPlaceListener` callback to ensure you detect places correctly. [block:code] { "codes": [ { "code": " MOCA.placesInside(function (e) {\n console.log(\"places inside: \");\n console.log(e);\n});\n", "language": "javascript" } ] } [/block]