{"id":43687814,"url":"https://github.com/NativeScript/push-plugin","last_synced_at":"2026-02-16T13:01:51.366Z","repository":{"id":35510863,"uuid":"39781030","full_name":"NativeScript/push-plugin","owner":"NativeScript","description":"Contains the source code for the Push Plugin.","archived":true,"fork":false,"pushed_at":"2019-01-07T13:25:04.000Z","size":25384,"stargazers_count":123,"open_issues_count":36,"forks_count":45,"subscribers_count":37,"default_branch":"master","last_synced_at":"2025-10-09T00:26:41.065Z","etag":null,"topics":["android","firebase-cloud-messaging","ios","mobile","nativescript","push-notifications"],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NativeScript.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-27T15:08:01.000Z","updated_at":"2025-04-02T06:44:07.000Z","dependencies_parsed_at":"2022-08-29T05:01:41.289Z","dependency_job_id":null,"html_url":"https://github.com/NativeScript/push-plugin","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/NativeScript/push-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fpush-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fpush-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fpush-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fpush-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NativeScript","download_url":"https://codeload.github.com/NativeScript/push-plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NativeScript%2Fpush-plugin/sbom","scorecard":{"id":99286,"data":{"date":"2025-08-11","repo":{"name":"github.com/NativeScript/push-plugin","commit":"160f378093c0421c75534e9e8bd0910c0c504b40"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":5,"checks":[{"name":"Code-Review","score":9,"reason":"Found 12/13 approved changesets -- score normalized to 9","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":8,"reason":"binaries present in source code","details":["Warn: binary detected: native-src/android/gradle/wrapper/gradle-wrapper.jar:1","Warn: binary detected: src/platforms/ios/PushPlugin.framework/PushPlugin:1"],"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":0,"reason":"project is archived","details":["Warn: Repository is archived."],"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: npmCommand not pinned by hash: publish/pack.sh:17","Warn: npmCommand not pinned by hash: publish/pack.sh:26","Info:   0 out of   2 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Apache License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/NativeScript/.github/SECURITY.md:1","Info: Found linked content: github.com/NativeScript/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/NativeScript/.github/SECURITY.md:1","Info: Found text in security policy: github.com/NativeScript/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-15T09:47:45.938Z","repository_id":35510863,"created_at":"2025-08-15T09:47:45.939Z","updated_at":"2025-08-15T09:47:45.939Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29508735,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","firebase-cloud-messaging","ios","mobile","nativescript","push-notifications"],"created_at":"2026-02-05T03:00:21.768Z","updated_at":"2026-02-16T13:01:51.360Z","avatar_url":"https://github.com/NativeScript.png","language":"Objective-C","readme":"# Push Plugin for NativeScript\r\n\r\n---\r\n**This plugin is deprecated.** Feel free to use the [Firebase Plugin](https://github.com/EddyVerbruggen/nativescript-plugin-firebase) for implementing push notifications in your NativeScript  app. If you already have an app that use the Push Plugin, read the [migrate-to-firebase doc](./MIGRATE-TO-FIREBASE.md) for initial guidance.\r\n\r\n---\r\n[![Build Status](https://travis-ci.org/NativeScript/push-plugin.svg?branch=master)](https://travis-ci.org/NativeScript/push-plugin)\r\n\r\nThe code for the Push Plugin for NativeScript.\r\n\r\n\u003c!-- TOC depthFrom:2 depthTo:3 --\u003e\r\n\r\n- [Installation](#installation)\r\n- [Configuration](#configuration)\r\n    - [Android](#android)\r\n    - [iOS](#ios)\r\n- [Usage](#usage)\r\n    - [Using the plugin in Android](#using-the-plugin-in-android)\r\n    - [Using the plugin in iOS](#using-the-plugin-in-ios)\r\n- [API Reference](#api-reference)\r\n    - [Methods](#methods)\r\n    - [Android only](#android-only)\r\n    - [iOS only](#ios-only)\r\n- [Troubleshooting](#troubleshooting)\r\n    - [Troubleshooting issues in Android](#troubleshooting-issues-in-android)\r\n    - [Troubleshooting issues in iOS](#troubleshooting-issues-in-ios)\r\n- [Android Configuration for using Firebase Cloud Messaging](#android-configuration-for-using-firebase-cloud-messaging)\r\n    - [Receive and Handle Messages from FCM on Android](#receive-and-handle-messages-from-fcm-on-android)\r\n- [Contribute](#contribute)\r\n- [Get Help](#get-help)\r\n\r\n\u003c!-- /TOC --\u003e\r\n\r\n## Installation\r\n\r\nIn the Command prompt / Terminal navigate to your application root folder and run:\r\n\r\n    tns plugin add nativescript-push-notifications\r\n\r\n## Configuration\r\n\r\n### Android\r\n\r\n\u003e See the [Android Configuration for using Firebase Cloud Messaging](#android-configuration-for-using-firebase-cloud-messaging) for information about how to add Firebase to your project.\r\n\r\n- Edit the `package.json` file in the root of application, by changing the bundle identifier to match the Firebase's project package name. For example:\r\n    ```json\r\n    \"id\": \"org.nativescript.PushNotificationApp\"\r\n    ```\r\n\r\n- Edit the `app/App_Resources/Android/app.gradle` file of your application, by changing the application ID to match the bundle identifier from the package.json. For example:\r\n    ```Groovy\r\n    android {\r\n    // ...\r\n        defaultConfig {\r\n            applicationId = \"org.nativescript.PushNotificationApp\"\r\n        }\r\n    // ...\r\n    }\r\n    ```\r\n\r\n- Go to the application folder and add the Android platform to the application\r\n    ```bash\r\n    tns platform add android\r\n    ```\r\n\r\n- Add the `google-settings.json` file with the FCM configuration to the `app/App_Resources/Android folder` in your app. If this file is not added, building the app for android will fail.\r\n\r\nThe plugin will default to version 12.0.1 of the `firebase-messaging` SDK.  If you need to change the version, you can add a project ext property `firebaseMessagingVersion`:\r\n\r\n```Groovy\r\n    // in the root level of /app/App_Resources/Android/app.gradle:\r\n    project.ext {\r\n        firebaseMessagingVersion = \"+\" // OR the version you wish\r\n    }\r\n```\r\n\r\n### iOS\r\n\r\n- Ensure you have set up an App in your Apple Developer account, with Push Notifications enabled and configured. More on this in the Apple's [AddingCapabilities documentation](https://developer.apple.com/library/content/documentation/IDEs/Conceptual/AppDistributionGuide/AddingCapabilities/AddingCapabilities.html) \u003e `Configuring Push Notifications` section.\r\n\r\n- Edit the package.json file in the root of application, by changing the bundle identifier to match the App ID. For example:\r\n    ```json\r\n    \"id\": \"org.nativescript.PushNotificationApp\"\r\n    ```\r\n\r\n- Go to the application folder and add the iOS platform to the application\r\n    ```bash\r\n    tns build ios\r\n    ```\r\n\r\n- Go to (application folder)/platforms/ios and open the XCode project. Enable Push Notifications in the project Capabilities options. In case you don't have XCode, go to (application folder)/platforms/ios/(application folder name) , find *.entitlements file and add to it `aps-environment` key and its value as shown below:\r\n    ```xml\r\n    \u003cplist version=\"1.0\"\u003e\r\n    \u003cdict\u003e\r\n        \u003ckey\u003eaps-environment\u003c/key\u003e\r\n        \u003cstring\u003edevelopment\u003c/string\u003e\r\n    \u003c/dict\u003e\r\n    \u003c/plist\u003e\r\n    ```\r\n\r\n## Usage\r\n\r\n### Using the plugin in Android\r\n\r\nAdd code in your view model or component to subscribe and receive messages (don't forget to enter your Firebase Cloud Messaging **Sender ID** in the options of the register method):\r\n\r\n#### TypeScript\r\n\r\n```TypeScript\r\nimport * as pushPlugin from \"nativescript-push-notifications\";\r\nprivate pushSettings = {\r\n    senderID: \"\u003cENTER_YOUR_PROJECT_NUMBER\u003e\", // Required: setting with the sender/project number\r\n    notificationCallbackAndroid: (stringifiedData: String, fcmNotification: any) =\u003e {\r\n        const notificationBody = fcmNotification \u0026\u0026 fcmNotification.getBody();\r\n        this.updateMessage(\"Message received!\\n\" + notificationBody + \"\\n\" + stringifiedData);\r\n    }\r\n};\r\npushPlugin.register(pushSettings, (token: String) =\u003e {\r\n    alert(\"Device registered. Access token: \" + token);;\r\n}, function() { });\r\n```\r\n\r\n#### Javascript\r\n\r\n```Javascript\r\nvar pushPlugin = require(\"nativescript-push-notifications\");\r\nvar pushSettings = {\r\n        senderID: \"\u003cENTER_YOUR_PROJECT_NUMBER\u003e\", // Required: setting with the sender/project number\r\n        notificationCallbackAndroid: function (stringifiedData, fcmNotification) {\r\n            var notificationBody = fcmNotification \u0026\u0026 fcmNotification.getBody();\r\n            _this.updateMessage(\"Message received!\\n\" + notificationBody + \"\\n\" + stringifiedData);\r\n        }\r\n    };\r\npushPlugin.register(pushSettings, function (token) {\r\n    alert(\"Device registered. Access token: \" + token);\r\n}, function() { });\r\n```\r\n\r\n- Run the app on the phone or emulator:\r\n    ```bash\r\n    tns run android\r\n    ```\r\n\r\n- The access token is written in the console and displayed on the device after the plugin sucessfully subscribes to receive notifications. When a notification comes, the message will be displayed in the notification area if the app is closed or handled directly in the notificationCallbackAndroid callback if the app is open.\r\n\r\n### Using the plugin in iOS\r\n\r\nAdd code in your view model or component to subscribe and receive messages:\r\n\r\n#### TypeScript\r\n\r\n```TypeScript\r\nimport * as pushPlugin from \"nativescript-push-notifications\";\r\nconst iosSettings = {\r\n    badge: true,\r\n    sound: true,\r\n    alert: true,\r\n    interactiveSettings: {\r\n        actions: [{\r\n            identifier: 'READ_IDENTIFIER',\r\n            title: 'Read',\r\n            activationMode: \"foreground\",\r\n            destructive: false,\r\n            authenticationRequired: true\r\n        }, {\r\n            identifier: 'CANCEL_IDENTIFIER',\r\n            title: 'Cancel',\r\n            activationMode: \"foreground\",\r\n            destructive: true,\r\n            authenticationRequired: true\r\n        }],\r\n        categories: [{\r\n            identifier: 'READ_CATEGORY',\r\n            actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],\r\n            actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']\r\n        }]\r\n    },\r\n    notificationCallbackIOS: (message: any) =\u003e {\r\n        alert(\"Message received!\\n\" + JSON.stringify(message));\r\n    }\r\n};\r\n\r\npushPlugin.register(iosSettings, (token: String) =\u003e {\r\n    alert(\"Device registered. Access token: \" + token);\r\n\r\n    // Register the interactive settings\r\n    if(iosSettings.interactiveSettings) {\r\n        pushPlugin.registerUserNotificationSettings(() =\u003e {\r\n            alert('Successfully registered for interactive push.');\r\n        }, (err) =\u003e {\r\n            alert('Error registering for interactive push: ' + JSON.stringify(err));\r\n        });\r\n    }\r\n}, (errorMessage: any) =\u003e {\r\n    alert(\"Device NOT registered! \" + JSON.stringify(errorMessage));\r\n});\r\n```\r\n\r\n#### Javascript\r\n\r\n```Javascript\r\nvar pushPlugin = require(\"nativescript-push-notifications\");\r\nvar iosSettings = {\r\n    badge: true,\r\n    sound: true,\r\n    alert: true,\r\n    interactiveSettings: {\r\n        actions: [{\r\n            identifier: 'READ_IDENTIFIER',\r\n            title: 'Read',\r\n            activationMode: \"foreground\",\r\n            destructive: false,\r\n            authenticationRequired: true\r\n        }, {\r\n            identifier: 'CANCEL_IDENTIFIER',\r\n            title: 'Cancel',\r\n            activationMode: \"foreground\",\r\n            destructive: true,\r\n            authenticationRequired: true\r\n        }],\r\n        categories: [{\r\n            identifier: 'READ_CATEGORY',\r\n            actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],\r\n            actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']\r\n        }]\r\n    },\r\n    notificationCallbackIOS: function (data) {\r\n        alert(\"message\", \"\" + JSON.stringify(data));\r\n    }\r\n};\r\n\r\npushPlugin.register(iosSettings, function (data) {\r\n    alert(\"Device registered. Access token\" + data);\r\n\r\n    // Register the interactive settings\r\n        if(iosSettings.interactiveSettings) {\r\n            pushPlugin.registerUserNotificationSettings(function() {\r\n                alert('Successfully registered for interactive push.');\r\n            }, function(err) {\r\n                alert('Error registering for interactive push: ' + JSON.stringify(err));\r\n            });\r\n        }\r\n}, function() { });\r\n```\r\n\r\n- Run the app on the phone or simulator:\r\n    ```bash\r\n    tns run ios\r\n    ```\r\n\r\n- [HINT] Install the [pusher app](https://github.com/noodlewerk/NWPusher) to send notifications to the device being debugged on. In the 'device push token' field paste the device access token generated in the {N} CLI / XCode debug console after launching the app.\r\n\r\n## API Reference\r\n\r\n### Methods\r\n\r\n#### register(options, successCallback, errorCallback) - subscribe the device with Apple/Google push notifications services so the app can receive notifications\r\n\r\n| Option | Platform | Type | Description |\r\n| --- |  --- | --- | --- |\r\n| senderID | Android | String | The Sender ID for the FCM project. This option is required for Android. |\r\n| notificationCallbackAndroid | Android | Function | Callback to invoke, when a push is received on Android. |\r\n| badge | iOS | Boolean | Enable setting the badge through Push Notification. |\r\n| sound | iOS | Boolean | Enable playing a sound. |\r\n| alert | iOS | Boolean | Enable creating a alert. |\r\n| clearBadge | iOS | Boolean | Enable clearing the badge on push registration. |\r\n| notificationCallbackIOS | iOS | Function | Callback to invoke, when a push is received on iOS. |\r\n| interactiveSettings | iOS | Object | Interactive settings for use when registerUserNotificationSettings is used on iOS. |\r\n\r\nThe interactiveSettings object for iOS can contain the following:\r\n\r\n| Option | Type | Description |\r\n| --- |  --- | --- |\r\n| actions | Array | A list of iOS interactive notification actions. |\r\n| categories | Array | A list of iOS interactive notification categories. |\r\n\r\nThe `actions` array from the iOS interactive settings contains:\r\n\r\n| Option | Type | Description |\r\n| --- |  --- | --- |\r\n| identifier | String | Required. String identifier of the action. |\r\n| title | String | Required. Title of the button action. |\r\n| activationMode | String | Set to either \"foreground\" or \"background\" to launch the app in foreground/background and respond to the action. |\r\n| destructive | Boolean | Enable if the action is destructive. Will change the action color to red instead of the default. |\r\n| authenticationRequired | Boolean | Enable if the device must be unlocked to perform the action. |\r\n| behavior | String | Set if the action has a different behavior - e.g. text input. |\r\n\r\nThe `categories` array from the iOS interactive settings contains:\r\n\r\n| Option | Type | Description |\r\n| --- |  --- | --- |\r\n| identifier | String | Required. String identifier of the category. |\r\n| actionsForDefaultContext | Array | Required. Array of string identifiers of actions. |\r\n| actionsForMinimalContext | Array | Required. Array of string identifiers of actions. |\r\n\r\nFor more information about iOS interactive notifications, please visit the [Apple Developer site](https://developer.apple.com/notifications/)\r\n\r\n```Javascript\r\nvar settings = {\r\n    badge: true,\r\n    sound: true,\r\n    alert: true,\r\n    interactiveSettings: {\r\n        actions: [{\r\n            identifier: 'READ_IDENTIFIER',\r\n            title: 'Read',\r\n            activationMode: \"foreground\",\r\n            destructive: false,\r\n            authenticationRequired: true\r\n        }, {\r\n        identifier: 'CANCEL_IDENTIFIER',\r\n            title: 'Cancel',\r\n            activationMode: \"foreground\",\r\n            destructive: true,\r\n            authenticationRequired: true\r\n        }],\r\n        categories: [{\r\n            identifier: 'READ_CATEGORY',\r\n            actionsForDefaultContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER'],\r\n            actionsForMinimalContext: ['READ_IDENTIFIER', 'CANCEL_IDENTIFIER']\r\n        }]\r\n    },\r\n    notificationCallbackIOS: function(message) {\r\n        alert(JSON.stringify(message));\r\n    }\r\n};\r\n\r\n\r\npushPlugin.register(settings,\r\n    // Success callback\r\n    function(token){\r\n        // Register the interactive settings\r\n        if(settings.interactiveSettings) {\r\n            pushPlugin.registerUserNotificationSettings(function() {\r\n                alert('Successfully registered for interactive push.');\r\n            }, function(err) {\r\n                alert('Error registering for interactive push: ' + JSON.stringify(err));\r\n            });\r\n        }\r\n    },\r\n    // Error Callback\r\n    function(error){\r\n        alert(error.message);\r\n    }\r\n);\r\n```\r\n\r\n#### unregister(successCallback, errorCallback, options) - unsubscribe the device so the app stops receiving push notifications. The options object is the same as on the `register` method\r\n\r\n| Parameter | Platform | Type | Description |\r\n| --- |  --- | --- | --- |\r\n| successCallback | iOS | Function | Called when app is successfully unsubscribed. Has one object parameter with the result. |\r\n| successCallback | Android | Function | Called when app is successfully unsubscribed. Has one string parameter with the result. |\r\n| errorCallback | Android | Function | Called when app is NOT successfully unsubscribed. Has one parameter containing the error. |\r\n| options | Android | Function | Called when app is NOT successfully unsubscribed. Has one parameter containing the error. |\r\n\r\n```Javascript\r\npushPlugin.unregister(\r\n    // Success callback\r\n    function(result) {\r\n        alert('Device unregistered successfully');\r\n    },\r\n    // Error Callback\r\n    function(errorMessage) {\r\n        alert(errorMessage);\r\n    },\r\n    // The settings from the registration phase\r\n    settings\r\n);\r\n```\r\n\r\n#### areNotificationsEnabled(successCallback) - check if push notifications are enabled (iOS only, always returns true on Android)\r\n\r\n| Parameter | Platform | Type | Description |\r\n| --- |  --- | --- | --- |\r\n| successCallback | iOS/Android | Function | Called with one boolean parameter containing the result from the notifications enabled check. |\r\n\r\n```Javascript\r\npushPlugin.areNotificationsEnabled(function(areEnabled) {\r\n        alert('Are Notifications enabled: ' + areEnabled);\r\n    });\r\n```\r\n\r\n### Android only\r\n\r\n#### onMessageReceived(callback) ***DEPRECATED*** - register a callback function to execute when receiving a notification. You should set this from the `notificationCallbackAndroid` registration option instead\r\n\r\n| Parameter | Type | Description |\r\n| --- |  --- | --- |\r\n| stringifiedData | String | A string containing JSON data from the notification |\r\n| fcmNotification | Object | iOS/Android | Function | The FCMNotification object. |\r\n\r\nThe fcmNotification object contains the following methods:\r\n\r\n| Method | Returns |\r\n| --- |  --- |\r\n| getBody() | String |\r\n| getBodyLocalizationArgs() | String[] |\r\n| getBodyLocalizationKey() | String |\r\n| getClickAction() | String |\r\n| getColor() | String |\r\n| getIcon() | String |\r\n| getSound() | String |\r\n| getTag() | String |\r\n| getTitle() | String |\r\n| getTitleLocalizationArgs() | String[] |\r\n| getTitleLocalizationKey() | String |\r\n\r\n#### onTokenRefresh(callback) - register a callback function to execute when the old token is revoked and a new token is obtained. Note that the token is _not_ passed to the callback as an argument. If you need the new token value, you'll need to call `register` again or add some native code to obtain the token from FCM\r\n\r\n| Parameter | Type | Description |\r\n| --- |  --- | --- |\r\n| callback | Function | Called with no arguments. |\r\n\r\n```Javascript\r\npushPlugin.onTokenRefresh(function() {\r\n        alert(\"new token obtained\");\r\n});\r\n```\r\n\r\n### iOS only\r\n\r\n#### registerUserNotificationSettings(successCallback, errorCallback) - used to register for interactive push on iOS\r\n\r\n| Parameter | Type | Description |\r\n| --- |  --- | --- |\r\n| successCallback | Function | Called when app is successfully unsubscribed. Has one object parameter with the result. |\r\n| errorCallback | Function | Called when app is NOT successfully unsubscribed. Has one parameter containing the error. |\r\n\r\n## Troubleshooting\r\n\r\nIn case the application doesn't work as expected. Here are some things you can verify\r\n\r\n### Troubleshooting issues in Android\r\n\r\n- When the application is started using `tns run android` (i.e. in debug mode with livesync) some background notifications might not be received correctly. This happens because the app is not started in a normal way for debugging and the resume from background happens differently. To receive all notifications correctly, stop the app (swipe it away it from the recent apps list) and start it again by tapping the app icon on the device.\r\n\r\n- Thе `google-services` plugin is added automatically. If this fails, you can try adding it manually:\r\n- - Navigate to the project `platforms/android/` folder and locate the application-level `build.gradle` file\r\n- - Add the `google-services` plugin to the list of other dependencies in your app's `build.gradle` file\r\n\t```Groovy\r\n\tdependencies {\r\n\t\t// ...\r\n\t\tclasspath \"com.google.gms:google-services:3.0.0\"\r\n\t\t// ...\r\n\t}\r\n\t```\r\n- - Add the following line be at the bottom of your `build.gradle` file to enable the Gradle plugin\r\n\t```Groovy\r\n\tapply plugin: 'com.google.gms.google-services'\r\n\t```\r\n\r\n- Ensure that the AndroidManifest.xml located at platforms/android/build/... (**do not add it in your \"App_Resources/Android/AndroidManifest.xml\" file**) contains the following snippets for registering the GCM listener:\r\n    ```XML\r\n    \u003cactivity android:name=\"com.telerik.pushplugin.PushHandlerActivity\"/\u003e\r\n    \u003creceiver\r\n        android:name=\"com.google.android.gms.gcm.GcmReceiver\"\r\n        android:exported=\"true\"\r\n        android:permission=\"com.google.android.c2dm.permission.SEND\" \u003e\r\n        \u003cintent-filter\u003e\r\n            \u003caction android:name=\"com.google.android.c2dm.intent.RECEIVE\" /\u003e\r\n            \u003ccategory android:name=\"com.pushApp.gcm\" /\u003e\r\n        \u003c/intent-filter\u003e\r\n    \u003c/receiver\u003e\r\n    \u003cservice\r\n        android:name=\"com.telerik.pushplugin.PushPlugin\"\r\n        android:exported=\"false\" \u003e\r\n        \u003cintent-filter\u003e\r\n            \u003caction android:name=\"com.google.android.c2dm.intent.RECEIVE\" /\u003e\r\n        \u003c/intent-filter\u003e\r\n    \u003c/service\u003e\r\n    ```\r\n\r\n- Ensure that the AndroidManifest.xml located at platforms/android/build/... contains the following permissions for push notifications:\r\n    ```xml\r\n    \u003cuses-permission android:name=\"android.permission.WAKE_LOCK\" /\u003e\r\n    \u003cuses-permission android:name=\"com.google.android.c2dm.permission.RECEIVE\" /\u003e\r\n    ```\r\n\r\n### Troubleshooting issues in iOS\r\n\r\n- Error \"Error registering: no valid 'aps-environment' entitlement string found for application\" - this means that the certificates are not correctly set in the xcodeproject. Open the xcodeproject, fix them and you can even run the application from xcode to verify it's setup correctly. The bundle identifier in xcode should be the same as the \"id\" in the package.json file in the root of the project. Also make sure that \"Push Notifications\" is switched ON in the \"Capabilities\" page of the project settings.\r\n\r\n## Android Configuration for using Firebase Cloud Messaging\r\n\r\nThe `nativescript-push-notifications` module for Android relies on the Firebase Cloud Messaging (FCM) SDK. In the steps below you will be guided to complete a few additional steps to prepare your Android app to receive push notifications from FCM.\r\n\r\n1. Add the `google-services.json` file\r\n\r\n    To use FCM, you need this file. It contains configurations and credentials for your Firebase project. To obtain this follow the instructions for adding Firebase to your project from the official [documentation](https://firebase.google.com/docs/android/setup). Scroll down to the **Manually add Firebase** section.\r\n\r\n    Place the file in your app's `App_Resources/Android` folder\r\n\r\n2. Obtain the FCM Server Key (optional)\r\n\r\n    This key is required to be able to send programmatically push notifications to your app. You can obtain this key from your Firebase project.\r\n\r\n### Receive and Handle Messages from FCM on Android\r\n\r\nThe plugin allows for handling **data**, **notification**, and messages that contain **both** payload keys which  for the purposes of this article are reffered to as **mixed**. More specifics on these messages are explained [here](https://firebase.google.com/docs/cloud-messaging/concept-options#notifications_and_data_messages).\r\n\r\nThe plugin extends the `FirebaseMessagingService` and overrides its `onMessageReceived` callback. In your app you need to use the `notificationCallbackAndroid` setting when calling the `register` method of the plugin.\r\n\r\nThe behavior of the callback in the module follows the behavior of the FCM service.\r\n\r\n#### Handling **Data** Messages\r\n\r\nThe `notificationCallbackAndroid` method of the plugin is called each time a `data` notification is received.\r\n\r\nIf the app is stopped or suspended, NO notification is constructed and placed in the tray. Tapping the app icon launches the app and invokes the `notificationCallbackAndroid` callback where you will receive the notification data.\r\n\r\nIf the app is active and in foreground, the `notificationCallbackAndroid` callback is invoked immediately with the notification data (fcmNotification).\r\n\r\n#### Handling **Notification** Messages\r\n\r\nIf the app is active and in foreground, it invokes the `notificationCallbackAndroid` callback with two arguments (stringifiedData, fcmNotification).\r\n\r\nIf the app is in background, a notification is put in the tray. When tapped, it launches the app, but does not invoke the `notificationCallbackAndroid` callback.\r\n\r\n#### Handling **Mixed** Messages\r\n\r\nMixed messages are messages that contain in their load both **data** and **notification** keys. When such message is received:\r\n\r\n- The app is in foreground, the `notificationCallbackAndroid` callback is invoked with parameters (stringifiedData, fcmNotification)\r\n- The app is in background, the `notificationCallbackAndroid` callback is not invoked. A notification is placed in the system tray. If the notification in the tray is tapped, the `data` part of the mixed message is available in the extras of the intent of the activity and are available in the respective [application event](https://docs.nativescript.org/core-concepts/application-lifecycle) of NativeScript.\r\n\r\nExample of handling the `data` part in the application *resume* event (e.g. the app was brought to the foreground from the notification):\r\n\r\n```Javascript\r\napplication.on(application.resumeEvent, function(args) {\r\n    if (args.android) {\r\n        var act = args.android;\r\n        var intent = act.getIntent();\r\n        var extras = intent.getExtras();\r\n        if (extras) {\r\n            // for (var key in extras) {\r\n            //     console.log(key + ' -\u003e ' + extras[key]);\r\n            // }\r\n            var msg = extras.get('someKey');\r\n        }\r\n    }\r\n});\r\n```\r\n\r\n#### Parameters of the notificationCallbackAndroid Callback\r\n\r\nDepending on the notification event and payload, the `notificationCallbackAndroid` callback is invoked with two arguments.\r\n\r\n- `stringifiedData` - *String*. A stringified JSON representation of the `data` value in the notification payload.\r\n- `fcmNotification` - `RemoteMessage.Notification`. A representation of the `RemoteMessage.Notification` class which can be accessed according to its public methods. This parameter is available in case the callback was called from a message with a `notification` key in the payload.\r\n\r\n#### Setting Notification Icon and Color\r\n\r\nThe plugin automatically handles some keys in the `data` object like `message`, `title`, `color`, `smallIcon`, `largeIcon` and uses them to construct a notification entry in the tray.\r\n\r\nCustom default color and icon for **notification** messages can be set in the `AndroidManifest.xml` inside the `application` directive:\r\n```XML\r\n\u003cmeta-data\r\n    android:name=\"com.google.firebase.messaging.default_notification_icon\"\r\n    android:resource=\"@drawable/ic_stat_ic_notification\" /\u003e\r\n\u003cmeta-data\r\n    android:name=\"com.google.firebase.messaging.default_notification_color\"\r\n    android:resource=\"@color/colorAccent\" /\u003e\r\n```\r\n\u003e For more info visit the [Edit the app manifest](https://firebase.google.com/docs/cloud-messaging/android/topic-messaging#edit-the-app-manifest) article.\r\n\r\n\r\n## Contribute\r\nWe love PRs! Check out the [contributing guidelines](CONTRIBUTING.md). If you want to contribute, but you are not sure where to start - look for [issues labeled `help wanted`](https://github.com/NativeScript/push-plugin/issues?q=is%3Aopen+is%3Aissue+label%3A%22help+wanted%22).\r\n\r\n## Get Help \r\nPlease, use [github issues](https://github.com/NativeScript/push-plugin/issues) strictly for [reporting bugs](CONTRIBUTING.md#reporting-bugs) or [requesting features](CONTRIBUTING.md#requesting-new-features). For general questions and support, check out [Stack Overflow](https://stackoverflow.com/questions/tagged/nativescript) or ask our experts in [NativeScript community Slack channel](http://developer.telerik.com/wp-login.php?action=slack-invitation).\r\n\r\n![](https://ga-beacon.appspot.com/UA-111455-24/nativescript/push-plugin?pixel)\r\n","funding_links":[],"categories":["Awesome {N} [![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)"],"sub_categories":["Table of Contents"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNativeScript%2Fpush-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNativeScript%2Fpush-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNativeScript%2Fpush-plugin/lists"}