{"__v":10,"_id":"55a8fb52c8bd450d000dd131","category":{"project":"5540ce1b31827a0d007ab1cc","version":"5540ce1c31827a0d007ab1cf","_id":"55b9ff5fd72d1e1900276a38","pages":[],"__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-30T10:41:35.298Z","from_sync":false,"order":19,"slug":"corona","title":"Corona"},"parentDoc":null,"project":"5540ce1b31827a0d007ab1cc","user":"55a5003a750a9a23005332b6","version":{"__v":31,"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","createdAt":"2015-04-29T12:27:08.390Z","releaseDate":"2015-04-29T12:27:08.390Z","categories":["5540ce1c31827a0d007ab1d0","5540d91bbb9e762d00f594ad","5540e5f131827a0d007ab212","5540e5febb9e762d00f594d3","5540e61331827a0d007ab213","5540e6195cf9682100d61afa","5540e62631827a0d007ab214","5540e63031827a0d007ab215","5540e63531827a0d007ab216","5540e63e5cf9682100d61afc","5540e6445cf9682100d61afd","5540e64a5cf9682100d61afe","55a4ff5b2e70c0250038050f","55acb28318eefd0d0071d504","55ae1abe8576b92300291c80","55ae453ef302af23000ac109","55af586d555b900d0036d296","55af91dac8a85321007a53c3","55b9fee204775a2f00628071","55b9ff0e04775a2f00628072","55b9ff4604775a2f00628073","55b9ff5fd72d1e1900276a38","55b9ff7f04775a2f00628074","55b9ff90eb08801900f833e5","55b9ffa5d72d1e1900276a39","55b9ffca04775a2f00628075","55b9fffdd72d1e1900276a3a","56bc2f033ee9e70d008b46af","56c2f6efbbf9ec2d00e0fe4f","57595bbb18760817001e8bbe","57d8d9793916800e003dde53"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-17T12:55:46.989Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Supports iOS, Android\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"iOS Simulator can neither subscribe nor receive push notifications.\\nAndroid Emulator works fine though.\",\n  \"title\": \"Note:\"\n}\n[/block]\n[**Download Sample**](https://github.com/Pushwoosh/pushwoosh-corona-sdk)\n\nTo integrate Pushwoosh into your Corona application you need to do simple following steps:\n\n**1. Configure your Corona project**\n\nThe first thing you need to do is make sure a specific table is included within your **config.lua** file. You can simply copy/paste from the example, but ensure that the ‘notification’ table is within the ‘application’ table, not the ‘content’ table.\n\n**config.lua:** \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"application =\\n{\\n    content =\\n    {\\n        width = 320,\\n        height = 480\\n    },\\n \\n    notification =\\n    {\\n        google = { projectNumber = \\\"YOUR_GOOGLE_PROJECT_NUMBER_HERE\\\" },\\n        iphone =\\n        {\\n            types =\\n            {\\n                \\\"badge\\\", \\\"sound\\\", \\\"alert\\\"\\n            }\\n        }\\n    }\\n}\",\n      \"language\": \"lua\",\n      \"name\": \"config.lua - iOS\"\n    }\n  ]\n}\n[/block]\nThe presence of a ‘notification’ table in your **config.lua** file will trigger the “Do you wish to allow ‘Your App’ to receive Push Notifications?” popup on iOS when the user first launches your app.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"Replace \\\"YOUR_GOOGLE_PROJECT_NUMBER_HERE\\\" with your real Google Project Number.\"\n}\n[/block]\n**2. Add notification plugin and permissions for Android to your build.settings file**\n\n**build.settings**\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\\nsettings = \\n{\\n\\tplugins =\\n\\t{\\n\\t\\t[\\\"plugin.notifications\\\"] =\\n\\t\\t{\\n\\t\\t\\tpublisherId = \\\"com.coronalabs\\\"\\n\\t\\t},\\n\\t},\\n\\torientation =\\n\\t{\\n\\t\\tdefault = \\\"portrait\\\",\\n\\t\\tsupported = { \\\"portrait\\\" }\\n\\t},\\n  android =\\n\\t{\\n\\t\\tpermissions =\\n\\t\\t{\\n\\t\\t\\t{ name = \\\".permission.C2D_MESSAGE\\\", protectionLevel = \\\"signature\\\" },\\n\\t\\t},\\n\\t\\tusesPermissions =\\n\\t\\t{\\n\\t\\t\\t\\\"android.permission.INTERNET\\\",\\n\\t\\t\\t\\\"android.permission.GET_ACCOUNTS\\\",\\n\\t\\t\\t\\\"android.permission.RECEIVE_BOOT_COMPLETED\\\",\\n\\t\\t\\t\\\"com.google.android.c2dm.permission.RECEIVE\\\",\\n\\t\\t\\t\\\".permission.C2D_MESSAGE\\\",\\n\\t\\t},\\n\\t},\\n}\\n\",\n      \"language\": \"lua\",\n      \"name\": \"build.settings\"\n    }\n  ]\n}\n[/block]\n**3. Download Pushwoosh module from https://github.com/Pushwoosh/pushwoosh-corona-sdk/blob/master/pushwoosh.lua**\n\n**4. Add push notification handling code to your main.lua file:**\n\n**main.lua**: \n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"local pushwoosh = require( \\\"pushwoosh\\\" )\\n\\nlocal function onNotification( event )\\n\\tnative.showAlert( \\\"remote notification\\\", json.encode( event.data ), { \\\"OK\\\" } )\\nend\\n\\nlocal function onRegistrationSuccess( event )\\n\\tprint( \\\"Registered on Pushwoosh\\\" )\\nend\\n\\nlocal function onRegistrationFail( event )\\n\\tnative.showAlert( \\\"Notification Registration Failed\\\", \\\"An Error Contacting the Server has Occurred. Please try again later from the application settings.\\\", { \\\"OK\\\" } )                  \\nend\\n\\nRuntime:addEventListener( \\\"pushwoosh-notification\\\", onNotification )\\nRuntime:addEventListener( \\\"pushwoosh-registration-success\\\", onRegistrationSuccess )\\nRuntime:addEventListener( \\\"pushwoosh-registration-fail\\\", onRegistrationFail )\\n\\nlocal launchArgs = ...\\n\\npushwoosh.registerForPushNotifications( \\\"PUSHWOOSH_APPLICATION_ID\\\", launchArgs ) -- specify your application Id\",\n      \"language\": \"lua\",\n      \"name\": \"main.lua\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"Replace \\\"PUSHWOOSH_APPLICATION_ID\\\" with your real Pushwoosh Application ID.\"\n}\n[/block]\nThat’s it! Easy, isn’t it?\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"Please refer to https://docs.coronalabs.com/guide/events/appNotification/index.html for more information.\"\n}\n[/block]","excerpt":"How to integrate Pushwoosh SDK into your Corona project","slug":"corona-sdk","type":"basic","title":"Corona SDK"}

Corona SDK

How to integrate Pushwoosh SDK into your Corona project

[block:callout] { "type": "success", "title": "Supports iOS, Android" } [/block] [block:callout] { "type": "info", "body": "iOS Simulator can neither subscribe nor receive push notifications.\nAndroid Emulator works fine though.", "title": "Note:" } [/block] [**Download Sample**](https://github.com/Pushwoosh/pushwoosh-corona-sdk) To integrate Pushwoosh into your Corona application you need to do simple following steps: **1. Configure your Corona project** The first thing you need to do is make sure a specific table is included within your **config.lua** file. You can simply copy/paste from the example, but ensure that the ‘notification’ table is within the ‘application’ table, not the ‘content’ table. **config.lua:** [block:code] { "codes": [ { "code": "application =\n{\n content =\n {\n width = 320,\n height = 480\n },\n \n notification =\n {\n google = { projectNumber = \"YOUR_GOOGLE_PROJECT_NUMBER_HERE\" },\n iphone =\n {\n types =\n {\n \"badge\", \"sound\", \"alert\"\n }\n }\n }\n}", "language": "lua", "name": "config.lua - iOS" } ] } [/block] The presence of a ‘notification’ table in your **config.lua** file will trigger the “Do you wish to allow ‘Your App’ to receive Push Notifications?” popup on iOS when the user first launches your app. [block:callout] { "type": "warning", "body": "Replace \"YOUR_GOOGLE_PROJECT_NUMBER_HERE\" with your real Google Project Number." } [/block] **2. Add notification plugin and permissions for Android to your build.settings file** **build.settings** [block:code] { "codes": [ { "code": "\nsettings = \n{\n\tplugins =\n\t{\n\t\t[\"plugin.notifications\"] =\n\t\t{\n\t\t\tpublisherId = \"com.coronalabs\"\n\t\t},\n\t},\n\torientation =\n\t{\n\t\tdefault = \"portrait\",\n\t\tsupported = { \"portrait\" }\n\t},\n android =\n\t{\n\t\tpermissions =\n\t\t{\n\t\t\t{ name = \".permission.C2D_MESSAGE\", protectionLevel = \"signature\" },\n\t\t},\n\t\tusesPermissions =\n\t\t{\n\t\t\t\"android.permission.INTERNET\",\n\t\t\t\"android.permission.GET_ACCOUNTS\",\n\t\t\t\"android.permission.RECEIVE_BOOT_COMPLETED\",\n\t\t\t\"com.google.android.c2dm.permission.RECEIVE\",\n\t\t\t\".permission.C2D_MESSAGE\",\n\t\t},\n\t},\n}\n", "language": "lua", "name": "build.settings" } ] } [/block] **3. Download Pushwoosh module from https://github.com/Pushwoosh/pushwoosh-corona-sdk/blob/master/pushwoosh.lua** **4. Add push notification handling code to your main.lua file:** **main.lua**: [block:code] { "codes": [ { "code": "local pushwoosh = require( \"pushwoosh\" )\n\nlocal function onNotification( event )\n\tnative.showAlert( \"remote notification\", json.encode( event.data ), { \"OK\" } )\nend\n\nlocal function onRegistrationSuccess( event )\n\tprint( \"Registered on Pushwoosh\" )\nend\n\nlocal function onRegistrationFail( event )\n\tnative.showAlert( \"Notification Registration Failed\", \"An Error Contacting the Server has Occurred. Please try again later from the application settings.\", { \"OK\" } ) \nend\n\nRuntime:addEventListener( \"pushwoosh-notification\", onNotification )\nRuntime:addEventListener( \"pushwoosh-registration-success\", onRegistrationSuccess )\nRuntime:addEventListener( \"pushwoosh-registration-fail\", onRegistrationFail )\n\nlocal launchArgs = ...\n\npushwoosh.registerForPushNotifications( \"PUSHWOOSH_APPLICATION_ID\", launchArgs ) -- specify your application Id", "language": "lua", "name": "main.lua" } ] } [/block] [block:callout] { "type": "warning", "body": "Replace \"PUSHWOOSH_APPLICATION_ID\" with your real Pushwoosh Application ID." } [/block] That’s it! Easy, isn’t it? [block:callout] { "type": "info", "body": "Please refer to https://docs.coronalabs.com/guide/events/appNotification/index.html for more information." } [/block]