{"_id":"55a8f59ac8bd450d000dd11f","category":{"_id":"55b9fee204775a2f00628071","project":"5540ce1b31827a0d007ab1cc","__v":0,"version":"5540ce1c31827a0d007ab1cf","pages":[],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-07-30T10:39:30.778Z","from_sync":false,"order":16,"slug":"unity","title":"Unity"},"parentDoc":null,"__v":25,"user":"55a5003a750a9a23005332b6","version":{"_id":"5540ce1c31827a0d007ab1cf","project":"5540ce1b31827a0d007ab1cc","__v":31,"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"},"project":"5540ce1b31827a0d007ab1cc","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-07-17T12:31:22.623Z","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, Amazon, Windows Store Apps (Windows 8.1/Phone 8.1/Windows 10)\"\n}\n[/block]\n[**Download Plugin**](https://github.com/Pushwoosh/pushwoosh-unity)\n[**Download Sample**](https://github.com/Pushwoosh/pushwoosh-unity/tree/master/PushwooshUnitySample)\n[**Plugin Docs**](https://github.com/Pushwoosh/pushwoosh-unity/tree/master/Documentation) \n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"iOS Simulator can neither subscribe nor receive push notifications.\",\n  \"title\": \"Note:\"\n}\n[/block]\nTo integrate Pushwoosh into your Unity application you need to do simple following steps:\n\n1. Import [Unity push notification plugin](https://github.com/Pushwoosh/pushwoosh-unity) into your **assets** folder in Unity.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"title\": \"unitypackage:\",\n  \"body\": \"If *Pushwoosh.unitypackage* import fails, copy *Assets/Editor*, *Assets/Plugins*, *Assets/Pushwoosh* folders from the Sample Project into yours.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"AndroidManifest.xml changes\",\n  \"body\": \"Merge contents of **Assets/Plugins/Android/PushwooshAndroidManifest.xml** into **Assets/Plugins/Android/AndroidManifest.xml**. If you don't already have an Android Manifest, rename PushwooshAndroidManifest.xml to AndroidManifest.xml.\\nReplace **PACKAGE_NAME** with your project package. Note that in Unity it is called **‘Bundle Identifier’**.\"\n}\n[/block]\n3. Create **PushNotificator.cs** script and attach it to **Camera Object** in the scene.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using UnityEngine;\\nusing System.Collections;\\n \\npublic class PushNotificator : MonoBehaviour {\\n    // use for initialization\\n    void Start () {\\n        Pushwoosh.ApplicationCode = \\\"ENTER_PUSHWOOSH_APP_ID_HERE\\\";\\n        Pushwoosh.GcmProjectNumber = \\\"ENTER_FCM_SENDER_ID_HERE\\\";\\n        Pushwoosh.Instance.OnRegisteredForPushNotifications += OnRegisteredForPushNotifications;\\n        Pushwoosh.Instance.OnFailedToRegisteredForPushNotifications += OnFailedToRegisteredForPushNotifications;\\n        Pushwoosh.Instance.OnPushNotificationsReceived += OnPushNotificationsReceived;\\n      \\tPushwoosh.Instance.RegisterForPushNotifications ();\\n    }\\n \\n    void OnRegisteredForPushNotifications(string token)\\n    {\\n        // handle here\\n        Debug.Log(\\\"Received token: \\\\n\\\" + token);\\n    }\\n     \\n    void OnFailedToRegisteredForPushNotifications(string error)\\n    {\\n        // handle here\\n        Debug.Log(\\\"Error ocurred while registering to push notifications: \\\\n\\\" + error);\\n    }\\n     \\n    void OnPushNotificationsReceived(string payload)\\n    {\\n        // handle here\\n        Debug.Log(\\\"Received push notificaiton: \\\\n\\\" + payload);\\n    }\\n}\",\n      \"language\": \"csharp\"\n    }\n  ]\n}\n[/block]\nThat’s it! How easy is that?\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"**ApplicationCode** and **GcmProjectNumber** should be set before first **Pushwoosh.Instance** method call\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"To hide notification alerts when the application is in the foreground, simply set Pushwoosh_SHOW_ALERT value to NO in your Info.plist\",\n  \"title\": \"iOS extras\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"XCode 8\",\n  \"body\": \"XCode 8 requires **Push Notifications** to be enabled in **Capabilities** section in order to register for push notfications.\"\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/9bfe20a-Screen_Shot_2016-09-20_at_14.39.50.png\",\n        \"Screen Shot 2016-09-20 at 14.39.50.png\",\n        751,\n        181,\n        \"#d8d7d2\"\n      ]\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Android extras\",\n  \"body\": \"To receive push notifications on Android when the application is active without posting the notification to the notification center, set the following line in AndroidManifest.xml to true:\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<meta-data android:name=\\\"PW_BROADCAST_PUSH\\\" android:value=\\\"true\\\" />\",\n      \"language\": \"xml\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Amazon API Key\",\n  \"body\": \"Get the API KEY from Amazon according to the [Amazon guide](https://developer.amazon.com/sdk/adm/credentials.html).\\nFor a pre-release or “debug” version of your app, you must create an API Key and store it as the only data in a file named api_key.txt . **The api_key.txt file must be located inside the assets folder for your project.**\\nNote: ADM cannot recognize your API Key if it contains any spaces or line breaks.\\nFor a release or “production” version of your app, you may not need to create an API Key. Only if you sign the release version of your app using your own certificate, must you create an additional API Key for the release version of your app. Otherwise, if you allow Amazon to sign your app on your behalf, you do not need to create an additional API Key.\"\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"Windows Store Apps\",\n  \"body\": \"Follow the guide below\"\n}\n[/block]\nYou might need to select **WSAPlayer **platform for the libraries in Plugins/WSA as per screenshot below.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/0NlbP1uVSPCemNHvN1jY_Untitled.png\",\n        \"Untitled.png\",\n        \"1081\",\n        \"895\",\n        \"#7f2a44\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]\nYou also need to **Associate App with the Store** in exported Visual Studio project. And don't forget to set **Notifications->Toast Capable** in the project manifest.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/zcF9SCHMTuqJcIvHRkvh_Untitled3.png\",\n        \"Untitled3.png\",\n        \"727\",\n        \"1051\",\n        \"#3a5277\",\n        \"\"\n      ]\n    }\n  ]\n}\n[/block]","excerpt":"Integrating Pushwoosh SDK into your Unity project","slug":"unity-plugin","type":"basic","title":"Unity Plugin"}

Unity Plugin

Integrating Pushwoosh SDK into your Unity project

[block:callout] { "type": "success", "title": "Supports iOS, Android, Amazon, Windows Store Apps (Windows 8.1/Phone 8.1/Windows 10)" } [/block] [**Download Plugin**](https://github.com/Pushwoosh/pushwoosh-unity) [**Download Sample**](https://github.com/Pushwoosh/pushwoosh-unity/tree/master/PushwooshUnitySample) [**Plugin Docs**](https://github.com/Pushwoosh/pushwoosh-unity/tree/master/Documentation) [block:callout] { "type": "info", "body": "iOS Simulator can neither subscribe nor receive push notifications.", "title": "Note:" } [/block] To integrate Pushwoosh into your Unity application you need to do simple following steps: 1. Import [Unity push notification plugin](https://github.com/Pushwoosh/pushwoosh-unity) into your **assets** folder in Unity. [block:callout] { "type": "warning", "title": "unitypackage:", "body": "If *Pushwoosh.unitypackage* import fails, copy *Assets/Editor*, *Assets/Plugins*, *Assets/Pushwoosh* folders from the Sample Project into yours." } [/block] [block:callout] { "type": "info", "title": "AndroidManifest.xml changes", "body": "Merge contents of **Assets/Plugins/Android/PushwooshAndroidManifest.xml** into **Assets/Plugins/Android/AndroidManifest.xml**. If you don't already have an Android Manifest, rename PushwooshAndroidManifest.xml to AndroidManifest.xml.\nReplace **PACKAGE_NAME** with your project package. Note that in Unity it is called **‘Bundle Identifier’**." } [/block] 3. Create **PushNotificator.cs** script and attach it to **Camera Object** in the scene. [block:code] { "codes": [ { "code": "using UnityEngine;\nusing System.Collections;\n \npublic class PushNotificator : MonoBehaviour {\n // use for initialization\n void Start () {\n Pushwoosh.ApplicationCode = \"ENTER_PUSHWOOSH_APP_ID_HERE\";\n Pushwoosh.GcmProjectNumber = \"ENTER_FCM_SENDER_ID_HERE\";\n Pushwoosh.Instance.OnRegisteredForPushNotifications += OnRegisteredForPushNotifications;\n Pushwoosh.Instance.OnFailedToRegisteredForPushNotifications += OnFailedToRegisteredForPushNotifications;\n Pushwoosh.Instance.OnPushNotificationsReceived += OnPushNotificationsReceived;\n \tPushwoosh.Instance.RegisterForPushNotifications ();\n }\n \n void OnRegisteredForPushNotifications(string token)\n {\n // handle here\n Debug.Log(\"Received token: \\n\" + token);\n }\n \n void OnFailedToRegisteredForPushNotifications(string error)\n {\n // handle here\n Debug.Log(\"Error ocurred while registering to push notifications: \\n\" + error);\n }\n \n void OnPushNotificationsReceived(string payload)\n {\n // handle here\n Debug.Log(\"Received push notificaiton: \\n\" + payload);\n }\n}", "language": "csharp" } ] } [/block] That’s it! How easy is that? [block:callout] { "type": "warning", "body": "**ApplicationCode** and **GcmProjectNumber** should be set before first **Pushwoosh.Instance** method call" } [/block] [block:callout] { "type": "info", "body": "To hide notification alerts when the application is in the foreground, simply set Pushwoosh_SHOW_ALERT value to NO in your Info.plist", "title": "iOS extras" } [/block] [block:callout] { "type": "info", "title": "XCode 8", "body": "XCode 8 requires **Push Notifications** to be enabled in **Capabilities** section in order to register for push notfications." } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/9bfe20a-Screen_Shot_2016-09-20_at_14.39.50.png", "Screen Shot 2016-09-20 at 14.39.50.png", 751, 181, "#d8d7d2" ] } ] } [/block] [block:callout] { "type": "info", "title": "Android extras", "body": "To receive push notifications on Android when the application is active without posting the notification to the notification center, set the following line in AndroidManifest.xml to true:" } [/block] [block:code] { "codes": [ { "code": "<meta-data android:name=\"PW_BROADCAST_PUSH\" android:value=\"true\" />", "language": "xml" } ] } [/block] [block:callout] { "type": "info", "title": "Amazon API Key", "body": "Get the API KEY from Amazon according to the [Amazon guide](https://developer.amazon.com/sdk/adm/credentials.html).\nFor a pre-release or “debug” version of your app, you must create an API Key and store it as the only data in a file named api_key.txt . **The api_key.txt file must be located inside the assets folder for your project.**\nNote: ADM cannot recognize your API Key if it contains any spaces or line breaks.\nFor a release or “production” version of your app, you may not need to create an API Key. Only if you sign the release version of your app using your own certificate, must you create an additional API Key for the release version of your app. Otherwise, if you allow Amazon to sign your app on your behalf, you do not need to create an additional API Key." } [/block] [block:callout] { "type": "info", "title": "Windows Store Apps", "body": "Follow the guide below" } [/block] You might need to select **WSAPlayer **platform for the libraries in Plugins/WSA as per screenshot below. [block:image] { "images": [ { "image": [ "https://files.readme.io/0NlbP1uVSPCemNHvN1jY_Untitled.png", "Untitled.png", "1081", "895", "#7f2a44", "" ] } ] } [/block] You also need to **Associate App with the Store** in exported Visual Studio project. And don't forget to set **Notifications->Toast Capable** in the project manifest. [block:image] { "images": [ { "image": [ "https://files.readme.io/zcF9SCHMTuqJcIvHRkvh_Untitled3.png", "Untitled3.png", "727", "1051", "#3a5277", "" ] } ] } [/block]