Commit 3e2631f3 authored by Chok's avatar Chok
Browse files

chok: init commit

parent 511add9c
Pipeline #20 failed with stages
in 0 seconds
# Change Log
## 3.0.1
**Fixes:**
* fix(android): add service exported flags w/ intent-filter (#173)
* fix(android): processPushBundle flipped returned value (#160)
* fix: doc typo (#159)
**Chores:**
* chore: correct Bower metadata to MIT license (#166)
* chore(npm): rebuilt package-lock.json & fix audit
**Docs:**
* doc: add 2.x and 3.x to PLATFORM_SUPPORT.md
## 3.0.0
**Overview:**
In this major release, there are many breaking changes to the Android platform. The primary changes in this release are dropping Android Support Library for AndroidX, updating the Google Services Gradle Plugin requirement, refactoring the code to Kotlin, and upgrading all other third-party libraries. See below for more details.
---
**Requirement Changes:**
* Cordova-Android: 9.x
---
**Libraries & Dependencie Updates and Changes:**
* Bumped `me.leolin:ShortcutBadger@1.1.22`
* Bumped `Google Services Gradle Plugin@4.3.8`
* Migrated from **Android Support Library** to **AndroidX**
* Added `androidx.core:core@1.6.+`
---
**Breaking:**
* feat!(android): migrate source code to kotlin w/ refactors (#123)
* kotlin@1.5.20
* add before_compile hookscript for cordova-android 9.x support
* converted all java files to kotlin
* updted target-dir path for kotlin files
* refactored with improved null checks
* removed some duplicated code
* updated logging (more logging & better tagging)¥
* feat!(android): bump platform requirements (#122)
* feat!(android): bump me.leolin:ShortcutBadger@1.1.22 (#121)
* feat!(android): bump Google Services Gradle Plugin@4.3.8 (#120)
* feat!(android): Migrate to AndroidX (#119)
* feat!(android): migrate ASL to AndroidX
* feat!(android): swap framework support-v13 w/ androidx.core
* feat!(android): force AndroidXEnabled to true
* feat!(android): bump androidx.core:core@1.6.+
* doc(android): add androidx core version
**Fixes:**
* fix(docs): update TS type import to new package name (#109)
**Chores:**
* chore: rebuilt package-lock.json (#131)
* chore: bump npm dev dependencies (#132) (#133)
* chore(npm): bump devDep, rebuild package-lock & fix audit (#110)
* chore(npm): bump devDep @cordova/eslint-config@^4.0.0 w/ fixes (#144)
**CI:**
* ci: remove old travis configs (#128)
* ci: add codacy badge (#129)
* ci: add gh-actions badge to readme (#130)
**Docs:**
* doc: fixed minor typo (#98)
## 2.0.0
**Overview:**
This release contains breaking changes. One of these needed changes resolved issues of restoring the plugin from npm.
With this breaking change, the `havesource-cordova-plugin-push` package name is no longer used. Please completely uninstall the old version before installing the new version. This will ensure that the correct package name `@havesource/cordova-plugin-push` is used.
There is also an update to the installation requirements:
| | Version |
| - | - |
| Cordova CLI | 10.0.0 |
| Cordova Android | 8.0.0 |
| **Cordova iOS** | **6.0.0** |
| CocoaPods | 1.8.0 |
**Breaking:**
* breaking(ios): requirement bump [#80](https://github.com/havesource/cordova-plugin-push/pull/80)
* breaking: fixed incorrect initial cordova-cli requirement [79333b2](https://github.com/havesource/cordova-plugin-push/commit/79333b25e1ff68fea377be499da91528c82fa21f)
**Feature:**
* feat(ios): force `cocoapods` cdn [#48](https://github.com/havesource/cordova-plugin-push/pull/48)
* feat(ios): support `firebase/messaging` dep version override [#47](https://github.com/havesource/cordova-plugin-push/pull/47)
**Chore:**
* chore(`npm`): rebuilt `package-lock.json` [67e4e4b](https://github.com/havesource/cordova-plugin-push/commit/67e4e4ba185511e60b4d85cae882c41dae1c9cc0)
* chore(`android`): remove duplicate code [#81](https://github.com/havesource/cordova-plugin-push/pull/81)
* chore: bump dev dependencies [#79](https://github.com/havesource/cordova-plugin-push/pull/79)
**CI & Docs:**
* ci(gh-actions): bump dependencies [#78](https://github.com/havesource/cordova-plugin-push/pull/78)
## 1.0.0
**Breaking:**
* breaking(android): bump fcm@18.+ [#19](https://github.com/havesource/cordova-plugin-push/pull/19)
* breaking(android): drop phonegap-plugin-multidex dependency [#21](https://github.com/havesource/cordova-plugin-push/pull/21)
* breaking(android): move clearAllNotifications to destroy from pause [#13](https://github.com/havesource/cordova-plugin-push/pull/13)
**Feature:**
* feat(android): notification data pass [#31](https://github.com/havesource/cordova-plugin-push/pull/31)
* feat(ios): support critical alert notifications [#12](https://github.com/havesource/cordova-plugin-push/pull/12)
* feat(ios): increase firebase framework to 6.32.2 [#42](https://github.com/havesource/cordova-plugin-push/pull/42)
* feat: remove cordova-support-google-services dependency [#8](https://github.com/havesource/cordova-plugin-push/pull/8)
**Fix:**
* fix(android): missing channel description crash [#53](https://github.com/havesource/cordova-plugin-push/pull/53)
* fix(android): Use app name for default channel [#49](https://github.com/havesource/cordova-plugin-push/pull/49)
* fix(android): enable lights when lightColor is set [#15](https://github.com/havesource/cordova-plugin-push/pull/15)
* fix(browser): corrected path to manifest file. [#32](https://github.com/havesource/cordova-plugin-push/pull/32)
**Chore:**
* chore(android): set requirement >= 8.0.0 [#52](https://github.com/havesource/cordova-plugin-push/pull/52)
* chore(android): cleanup & format [#26](https://github.com/havesource/cordova-plugin-push/pull/26)
* chore(android): bump com.android.support:support-v13:28.0.0 [#20](https://github.com/havesource/cordova-plugin-push/pull/20)
* chore(ios): use latest firebase library [#24](https://github.com/havesource/cordova-plugin-push/pull/24)
* chore(npm): rebuilt package-lock.json [#55](https://github.com/havesource/cordova-plugin-push/pull/55)
* chore(npm): properly configure for scope package [#33](https://github.com/havesource/cordova-plugin-push/pull/33)
* chore(type-definition): Update PushNotificationStatic [#14](https://github.com/havesource/cordova-plugin-push/pull/14)
* chore(github-pages): remove config [#4](https://github.com/havesource/cordova-plugin-push/pull/4)
* chore: update ticket management [#27](https://github.com/havesource/cordova-plugin-push/pull/27)
* chore: add missing build of push.js [#22](https://github.com/havesource/cordova-plugin-push/pull/22)
* chore: match plugin.xml version w/ package.json [#10](https://github.com/havesource/cordova-plugin-push/pull/10)
* chore: update xml namespace [#9](https://github.com/havesource/cordova-plugin-push/pull/9)
* chore: update version requirements [#7](https://github.com/havesource/cordova-plugin-push/pull/7)
* chore: update npm & git ignore list [#6](https://github.com/havesource/cordova-plugin-push/pull/6)
* chore: update plugin package [#1](https://github.com/havesource/cordova-plugin-push/pull/1)
* chore: remove unused dependencies [#2](https://github.com/havesource/cordova-plugin-push/pull/2)
**Refactor & Style:**
* refactor(eslint): update dependencies w/ fixes [#3](https://github.com/havesource/cordova-plugin-push/pull/3)
* style(md): format with md all in one (vscode) [#11](https://github.com/havesource/cordova-plugin-push/pull/11)
**CI & Docs:**
* ci(gh-actions): add workflow [#23](https://github.com/havesource/cordova-plugin-push/pull/23)
* ci: update travis configs [#5](https://github.com/havesource/cordova-plugin-push/pull/5)
* doc(android): enable & set notification light with lightColor [#54](https://github.com/havesource/cordova-plugin-push/pull/54)
* doc: cleanup docs [#51](https://github.com/havesource/cordova-plugin-push/pull/51)
* doc: update various markdown docs [#28](https://github.com/havesource/cordova-plugin-push/pull/28)
## Previous Change Log
Since this repo is a fork from the original Adobe PhoneGap push plugin, you can continue to read the previous changelog here:
https://github.com/havesource/cordova-plugin-push/blob/phonegap-2.3.0/CHANGELOG.md
Copyright 2012-2017 Adobe Systems
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Cordova Plugin Push
[![Node CI](https://github.com/havesource/cordova-plugin-push/actions/workflows/ci.yml/badge.svg)](https://github.com/havesource/cordova-plugin-push/actions/workflows/ci.yml) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/422c67b5e70c4a0eadae7b9fc794d3c1)](https://app.codacy.com/gh/havesource/cordova-plugin-push?utm_source=github.com&utm_medium=referral&utm_content=havesource/cordova-plugin-push&utm_campaign=Badge_Grade_Settings)
> Register and receive push notifications
# What is this?
This plugin offers support to receive and handle native push notifications with a **single unified API**.
This does not mean you will be able to send a single push message and have it arrive on devices running different operating systems. By default Android uses FCM and iOS uses APNS and their payloads are significantly different. Even if you are using FCM for both Android and iOS there are differences in the payload required for the plugin to work correctly. For Android **always** put your push payload in the `data` section of the push notification. For more information on why that is the case read [Notification vs Data Payload](https://github.com/havesource/cordova-plugin-push/blob/master/docs/PAYLOAD.md#notification-vs-data-payloads). For iOS follow the regular [FCM documentation](https://firebase.google.com/docs/cloud-messaging/http-server-ref).
This plugin does not provide a way to determine which platform you are running on. The best way to do that is use the `device.platform` property provided by [cordova-plugin-device](https://github.com/apache/cordova-plugin-device).
* [Reporting Issues](docs/ISSUES.md)
* [Installation](docs/INSTALLATION.md)
* [API reference](docs/API.md)
* [Typescript support](docs/TYPESCRIPT.md)
* [Examples](docs/EXAMPLES.md)
* [Platform support](docs/PLATFORM_SUPPORT.md)
* [Cloud build support (PG Build, IntelXDK)](docs/PHONEGAP_BUILD.md)
* [Push notification payload details](docs/PAYLOAD.md)
* [Contributing](.github/CONTRIBUTING.md)
* [License (MIT)](MIT-LICENSE)
# Do you like tutorial? You get tutorial!
* [PhoneGap Day US Push Workshop 2016 (using node-gcm)](http://macdonst.github.io/push-workshop/)
# Thanks to all our contributors
[<img alt="10ko" src="https://avatars1.githubusercontent.com/u/2706375?v=4&s=117" width="117">](https://github.com/10ko)[<img alt="TVolly" src="https://avatars3.githubusercontent.com/u/20628284?v=4&s=117" width="117">](https://github.com/TVolly)[<img alt="waptaxi" src="https://avatars2.githubusercontent.com/u/6575569?v=4&s=117" width="117">](https://github.com/waptaxi)[<img alt="viktormuller" src="https://avatars1.githubusercontent.com/u/8171222?v=4&s=117" width="117">](https://github.com/viktormuller)[<img alt="devgeeks" src="https://avatars0.githubusercontent.com/u/554999?v=4&s=117" width="117">](https://github.com/devgeeks)[<img alt="rastafan" src="https://avatars3.githubusercontent.com/u/7632849?v=4&s=117" width="117">](https://github.com/rastafan)
[<img alt="mdoelker" src="https://avatars1.githubusercontent.com/u/2145319?v=4&s=117" width="117">](https://github.com/mdoelker)[<img alt="markeeftb" src="https://avatars3.githubusercontent.com/u/3172570?v=4&s=117" width="117">](https://github.com/markeeftb)[<img alt="malwatte" src="https://avatars2.githubusercontent.com/u/2534778?v=4&s=117" width="117">](https://github.com/malwatte)[<img alt="madebycm" src="https://avatars3.githubusercontent.com/u/5081823?v=4&s=117" width="117">](https://github.com/madebycm)[<img alt="kelvinhokk" src="https://avatars0.githubusercontent.com/u/7766953?v=4&s=117" width="117">](https://github.com/kelvinhokk)[<img alt="keab42" src="https://avatars0.githubusercontent.com/u/1453371?v=4&s=117" width="117">](https://github.com/keab42)
[<img alt="jomarocas" src="https://avatars3.githubusercontent.com/u/5194064?v=4&s=117" width="117">](https://github.com/jomarocas)[<img alt="giuseppelt" src="https://avatars2.githubusercontent.com/u/7147291?v=4&s=117" width="117">](https://github.com/giuseppelt)[<img alt="ericb" src="https://avatars3.githubusercontent.com/u/19638?v=4&s=117" width="117">](https://github.com/ericb)[<img alt="eKazim" src="https://avatars3.githubusercontent.com/u/21195186?v=4&s=117" width="117">](https://github.com/eKazim)[<img alt="clementcontet" src="https://avatars1.githubusercontent.com/u/7261426?v=4&s=117" width="117">](https://github.com/clementcontet)[<img alt="yaswanthsvist" src="https://avatars0.githubusercontent.com/u/3897387?v=4&s=117" width="117">](https://github.com/yaswanthsvist)
[<img alt="Vabs28" src="https://avatars1.githubusercontent.com/u/8149036?v=4&s=117" width="117">](https://github.com/Vabs28)[<img alt="TillaTheHun0" src="https://avatars0.githubusercontent.com/u/8246360?v=4&s=117" width="117">](https://github.com/TillaTheHun0)[<img alt="tomasvarg" src="https://avatars0.githubusercontent.com/u/16196322?v=4&s=117" width="117">](https://github.com/tomasvarg)[<img alt="tobmaster" src="https://avatars1.githubusercontent.com/u/203823?v=4&s=117" width="117">](https://github.com/tobmaster)[<img alt="ThiagoBueno" src="https://avatars1.githubusercontent.com/u/3334244?v=4&s=117" width="117">](https://github.com/ThiagoBueno)[<img alt="szh" src="https://avatars2.githubusercontent.com/u/546965?v=4&s=117" width="117">](https://github.com/szh)
[<img alt="SharUpOff" src="https://avatars3.githubusercontent.com/u/26085497?v=4&s=117" width="117">](https://github.com/SharUpOff)[<img alt="smorstabilini" src="https://avatars0.githubusercontent.com/u/551983?v=4&s=117" width="117">](https://github.com/smorstabilini)[<img alt="fesor" src="https://avatars2.githubusercontent.com/u/172247?v=4&s=117" width="117">](https://github.com/fesor)[<img alt="GreyDekart" src="https://avatars2.githubusercontent.com/u/1793548?v=4&s=117" width="117">](https://github.com/GreyDekart)[<img alt="sebastiansier" src="https://avatars1.githubusercontent.com/u/3733454?v=4&s=117" width="117">](https://github.com/sebastiansier)[<img alt="olastor" src="https://avatars0.githubusercontent.com/u/7479641?v=4&s=117" width="117">](https://github.com/olastor)
[<img alt="tanansatpal" src="https://avatars2.githubusercontent.com/u/20103208?v=4&s=117" width="117">](https://github.com/tanansatpal)[<img alt="SandroGrzicic" src="https://avatars1.githubusercontent.com/u/200247?v=4&s=117" width="117">](https://github.com/SandroGrzicic)[<img alt="xorxor" src="https://avatars1.githubusercontent.com/u/1525525?v=4&s=117" width="117">](https://github.com/xorxor)[<img alt="rubenstolk" src="https://avatars2.githubusercontent.com/u/692644?v=4&s=117" width="117">](https://github.com/rubenstolk)[<img alt="roel-sluper" src="https://avatars0.githubusercontent.com/u/1556404?v=4&s=117" width="117">](https://github.com/roel-sluper)[<img alt="pataar" src="https://avatars3.githubusercontent.com/u/3403851?v=4&s=117" width="117">](https://github.com/pataar)
[<img alt="peteonrails" src="https://avatars1.githubusercontent.com/u/9593?v=4&s=117" width="117">](https://github.com/peteonrails)[<img alt="pjalbuquerque" src="https://avatars3.githubusercontent.com/u/4201558?v=4&s=117" width="117">](https://github.com/pjalbuquerque)[<img alt="NitroGhost" src="https://avatars0.githubusercontent.com/u/3674467?v=4&s=117" width="117">](https://github.com/NitroGhost)[<img alt="matrosov-nikita" src="https://avatars3.githubusercontent.com/u/12752587?v=4&s=117" width="117">](https://github.com/matrosov-nikita)[<img alt="Mikejo5000" src="https://avatars1.githubusercontent.com/u/11948536?v=4&s=117" width="117">](https://github.com/Mikejo5000)[<img alt="michellarcari" src="https://avatars2.githubusercontent.com/u/6429722?v=4&s=117" width="117">](https://github.com/michellarcari)
[<img alt="adamschachne" src="https://avatars2.githubusercontent.com/u/13020251?v=4&s=117" width="117">](https://github.com/adamschachne)[<img alt="alharding" src="https://avatars1.githubusercontent.com/u/926204?v=4&s=117" width="117">](https://github.com/alharding)[<img alt="albertleao" src="https://avatars0.githubusercontent.com/u/1950338?v=4&s=117" width="117">](https://github.com/albertleao)[<img alt="gotev" src="https://avatars0.githubusercontent.com/u/16792495?v=4&s=117" width="117">](https://github.com/gotev)[<img alt="Alex-Sessler" src="https://avatars0.githubusercontent.com/u/5779673?v=4&s=117" width="117">](https://github.com/Alex-Sessler)[<img alt="ben-8409" src="https://avatars1.githubusercontent.com/u/305724?v=4&s=117" width="117">](https://github.com/ben-8409)
[<img alt="bmwertman" src="https://avatars3.githubusercontent.com/u/2573903?v=4&s=117" width="117">](https://github.com/bmwertman)[<img alt="bmatto" src="https://avatars1.githubusercontent.com/u/1044422?v=4&s=117" width="117">](https://github.com/bmatto)[<img alt="countcain" src="https://avatars0.githubusercontent.com/u/1751150?v=4&s=117" width="117">](https://github.com/countcain)[<img alt="CookieCookson" src="https://avatars3.githubusercontent.com/u/3473396?v=4&s=117" width="117">](https://github.com/CookieCookson)[<img alt="cdorner" src="https://avatars3.githubusercontent.com/u/917733?v=4&s=117" width="117">](https://github.com/cdorner)[<img alt="colene" src="https://avatars3.githubusercontent.com/u/1613781?v=4&s=117" width="117">](https://github.com/colene)
[<img alt="cfsnyder" src="https://avatars3.githubusercontent.com/u/3925941?v=4&s=117" width="117">](https://github.com/cfsnyder)[<img alt="cmalard" src="https://avatars0.githubusercontent.com/u/1692136?v=4&s=117" width="117">](https://github.com/cmalard)[<img alt="dansumption" src="https://avatars2.githubusercontent.com/u/174105?v=4&s=117" width="117">](https://github.com/dansumption)[<img alt="dannywillems" src="https://avatars2.githubusercontent.com/u/6018454?v=4&s=117" width="117">](https://github.com/dannywillems)[<img alt="DrMoriarty" src="https://avatars1.githubusercontent.com/u/1177068?v=4&s=117" width="117">](https://github.com/DrMoriarty)[<img alt="eladmoshe" src="https://avatars1.githubusercontent.com/u/1702227?v=4&s=117" width="117">](https://github.com/eladmoshe)
[<img alt="mlabarca" src="https://avatars2.githubusercontent.com/u/4587965?v=4&s=117" width="117">](https://github.com/mlabarca)[<img alt="bromeostasis" src="https://avatars3.githubusercontent.com/u/3764641?v=4&s=117" width="117">](https://github.com/bromeostasis)[<img alt="filmaj" src="https://avatars0.githubusercontent.com/u/52645?v=4&s=117" width="117">](https://github.com/filmaj)[<img alt="geo242" src="https://avatars3.githubusercontent.com/u/7529238?v=4&s=117" width="117">](https://github.com/geo242)[<img alt="gbenvenuti" src="https://avatars3.githubusercontent.com/u/331314?v=4&s=117" width="117">](https://github.com/gbenvenuti)[<img alt="polyn0m" src="https://avatars2.githubusercontent.com/u/1258130?v=4&s=117" width="117">](https://github.com/polyn0m)
[<img alt="jacquesdev" src="https://avatars1.githubusercontent.com/u/7842197?v=4&s=117" width="117">](https://github.com/jacquesdev)[<img alt="janpio" src="https://avatars0.githubusercontent.com/u/183673?v=4&s=117" width="117">](https://github.com/janpio)[<img alt="jakari" src="https://avatars2.githubusercontent.com/u/2283862?v=4&s=117" width="117">](https://github.com/jakari)[<img alt="purplecabbage" src="https://avatars3.githubusercontent.com/u/46134?v=4&s=117" width="117">](https://github.com/purplecabbage)[<img alt="theaccordance" src="https://avatars3.githubusercontent.com/u/1813001?v=4&s=117" width="117">](https://github.com/theaccordance)[<img alt="jonas-m-" src="https://avatars3.githubusercontent.com/u/1147572?v=4&s=117" width="117">](https://github.com/jonas-m-)
[<img alt="Chuckytuh" src="https://avatars3.githubusercontent.com/u/1127199?v=4&s=117" width="117">](https://github.com/Chuckytuh)[<img alt="leonardobazico" src="https://avatars1.githubusercontent.com/u/5280179?v=4&s=117" width="117">](https://github.com/leonardobazico)[<img alt="loslislo-lshift" src="https://avatars0.githubusercontent.com/u/17316151?v=4&s=117" width="117">](https://github.com/loslislo-lshift)[<img alt="luka5" src="https://avatars2.githubusercontent.com/u/1176296?v=4&s=117" width="117">](https://github.com/luka5)[<img alt="mac89" src="https://avatars3.githubusercontent.com/u/2988607?v=4&s=117" width="117">](https://github.com/mac89)[<img alt="markokeeffe" src="https://avatars2.githubusercontent.com/u/1211393?v=4&s=117" width="117">](https://github.com/markokeeffe)
[<img alt="mbektchiev" src="https://avatars1.githubusercontent.com/u/5744783?v=4&s=117" width="117">](https://github.com/mbektchiev)[<img alt="goya" src="https://avatars1.githubusercontent.com/u/208774?v=4&s=117" width="117">](https://github.com/goya)[<img alt="slorber" src="https://avatars0.githubusercontent.com/u/749374?v=4&s=117" width="117">](https://github.com/slorber)[<img alt="daserge" src="https://avatars1.githubusercontent.com/u/4272078?v=4&s=117" width="117">](https://github.com/daserge)[<img alt="smdvdsn" src="https://avatars2.githubusercontent.com/u/507093?v=4&s=117" width="117">](https://github.com/smdvdsn)[<img alt="ryanluker" src="https://avatars2.githubusercontent.com/u/1335972?v=4&s=117" width="117">](https://github.com/ryanluker)
[<img alt="russellbeattie" src="https://avatars1.githubusercontent.com/u/166835?v=4&s=117" width="117">](https://github.com/russellbeattie)[<img alt="rjmunro" src="https://avatars0.githubusercontent.com/u/108641?v=4&s=117" width="117">](https://github.com/rjmunro)[<img alt="hanicker" src="https://avatars3.githubusercontent.com/u/510258?v=4&s=117" width="117">](https://github.com/hanicker)[<img alt="mwbrooks" src="https://avatars1.githubusercontent.com/u/21328?v=4&s=117" width="117">](https://github.com/mwbrooks)[<img alt="LightZam" src="https://avatars3.githubusercontent.com/u/5077142?v=4&s=117" width="117">](https://github.com/LightZam)[<img alt="laagland" src="https://avatars3.githubusercontent.com/u/7661210?v=4&s=117" width="117">](https://github.com/laagland)
[<img alt="cuatl" src="https://avatars1.githubusercontent.com/u/1399392?v=4&s=117" width="117">](https://github.com/cuatl)[<img alt="gianpaj" src="https://avatars3.githubusercontent.com/u/899175?v=4&s=117" width="117">](https://github.com/gianpaj)[<img alt="EdMcBane" src="https://avatars1.githubusercontent.com/u/8511142?v=4&s=117" width="117">](https://github.com/EdMcBane)[<img alt="chriswiggins" src="https://avatars0.githubusercontent.com/u/2830609?v=4&s=117" width="117">](https://github.com/chriswiggins)[<img alt="barryvdh" src="https://avatars2.githubusercontent.com/u/973269?v=4&s=117" width="117">](https://github.com/barryvdh)[<img alt="armno" src="https://avatars3.githubusercontent.com/u/911894?v=4&s=117" width="117">](https://github.com/armno)
[<img alt="archananaik" src="https://avatars2.githubusercontent.com/u/5604248?v=4&s=117" width="117">](https://github.com/archananaik)[<img alt="jakub-g" src="https://avatars2.githubusercontent.com/u/1437027?v=4&s=117" width="117">](https://github.com/jakub-g)[<img alt="shazron" src="https://avatars0.githubusercontent.com/u/36107?v=4&s=117" width="117">](https://github.com/shazron)[<img alt="sclement41" src="https://avatars0.githubusercontent.com/u/443136?v=4&s=117" width="117">](https://github.com/sclement41)[<img alt="hung-doan" src="https://avatars1.githubusercontent.com/u/11371581?v=4&s=117" width="117">](https://github.com/hung-doan)[<img alt="BBosman" src="https://avatars3.githubusercontent.com/u/5115488?v=4&s=117" width="117">](https://github.com/BBosman)
[<img alt="giordanocardillo" src="https://avatars3.githubusercontent.com/u/3403386?v=4&s=117" width="117">](https://github.com/giordanocardillo)[<img alt="mikepsinn" src="https://avatars3.githubusercontent.com/u/2808553?v=4&s=117" width="117">](https://github.com/mikepsinn)[<img alt="AdriVanHoudt" src="https://avatars1.githubusercontent.com/u/2361826?v=4&s=117" width="117">](https://github.com/AdriVanHoudt)[<img alt="alexislg2" src="https://avatars1.githubusercontent.com/u/7933080?v=4&s=117" width="117">](https://github.com/alexislg2)[<img alt="jcesarmobile" src="https://avatars3.githubusercontent.com/u/1637892?v=4&s=117" width="117">](https://github.com/jcesarmobile)[<img alt="nadyaA" src="https://avatars2.githubusercontent.com/u/6064810?v=4&s=117" width="117">](https://github.com/nadyaA)
[<img alt="jdhiro" src="https://avatars0.githubusercontent.com/u/2919453?v=4&s=117" width="117">](https://github.com/jdhiro)[<img alt="edewit" src="https://avatars1.githubusercontent.com/u/51133?v=4&s=117" width="117">](https://github.com/edewit)[<img alt="wildabeast" src="https://avatars1.githubusercontent.com/u/118985?v=4&s=117" width="117">](https://github.com/wildabeast)[<img alt="mkuklis" src="https://avatars2.githubusercontent.com/u/63545?v=4&s=117" width="117">](https://github.com/mkuklis)[<img alt="ashconnell" src="https://avatars2.githubusercontent.com/u/760516?v=4&s=117" width="117">](https://github.com/ashconnell)[<img alt="zwacky" src="https://avatars1.githubusercontent.com/u/1093032?v=4&s=117" width="117">](https://github.com/zwacky)
[<img alt="rakatyal" src="https://avatars2.githubusercontent.com/u/12533467?v=4&s=117" width="117">](https://github.com/rakatyal)[<img alt="jtbdevelopment" src="https://avatars3.githubusercontent.com/u/2074134?v=4&s=117" width="117">](https://github.com/jtbdevelopment)[<img alt="EddyVerbruggen" src="https://avatars1.githubusercontent.com/u/1426370?v=4&s=117" width="117">](https://github.com/EddyVerbruggen)[<img alt="fredgalvao" src="https://avatars2.githubusercontent.com/u/616464?v=4&s=117" width="117">](https://github.com/fredgalvao)[<img alt="bobeast" src="https://avatars0.githubusercontent.com/u/441403?v=4&s=117" width="117">](https://github.com/bobeast)[<img alt="macdonst" src="https://avatars1.githubusercontent.com/u/353180?v=4&s=117" width="117">](https://github.com/macdonst)
[<img alt="larrybahr" src="https://avatars1.githubusercontent.com/u/8782684?v=4&s=117" width="117">](https://github.com/larrybahr)
# Cordova Plugin Push
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin http://dev.silverlakemobility.com/gitlab/cordova-custom/cordova-plugin-push.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](http://dev.silverlakemobility.com/gitlab/cordova-custom/cordova-plugin-push/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
const { join } = require('path');
const { existsSync, readFileSync, writeFileSync } = require('fs');
const { parseElementtreeSync: ParseElementtreeSync } = require('cordova-common/src/util/xml-helpers');
const platform = require('cordova-android');
module.exports = function (context) {
if (!isExecutable()) {
console.log('[cordova-plugin-push::before-compile] skipping before_compile hookscript.');
return;
}
const buildGradleFilePath = join(context.opts.projectRoot, 'platforms/android/build.gradle');
if (!existsSync(buildGradleFilePath)) {
console.log('[cordova-plugin-push::before-compile] could not find "build.gradle" file.');
return;
}
updateBuildGradle(context, buildGradleFilePath);
};
/**
* This hookscript is executable only when the platform version less then 10.x
* @returns Boolean
*/
function isExecutable () {
const majorVersion = parseInt(platform.version(), 10);
return majorVersion < 10 && majorVersion >= 9;
}
function getPluginKotlinVersion (context) {
const pluginConfig = new ParseElementtreeSync(join(context.opts.projectRoot, 'plugins/@havesource/cordova-plugin-push/plugin.xml'));
return pluginConfig
.findall('./platform[@name="android"]').pop()
.findall('./config-file[@target="config.xml"]').pop()
.findall('preference').filter(
elem => elem.attrib.name.toLowerCase() === 'GradlePluginKotlinVersion'.toLowerCase()
).pop().attrib.value;
}
function updateBuildGradle (context, buildGradleFilePath) {
const kotlinVersion = getPluginKotlinVersion(context);
const updateContent = readFileSync(buildGradleFilePath, 'utf8')
.replace(/ext.kotlin_version = ['"](.*)['"]/g, `ext.kotlin_version = '${kotlinVersion}'`);
writeFileSync(buildGradleFilePath, updateContent);
console.log(`[cordova-plugin-push::before-compile] updated "build.gradle" file with kotlin version set to: ${kotlinVersion}`);
}
module.exports = function (context) {
console.log('Updating manifest.json with push properties…');
var path = require('path');
var fs = require('fs');
var platformProjPath = path.join(
context.opts.projectRoot,
'platforms/browser'
);
if (!fs.existsSync(platformProjPath)) {
platformProjPath = context.opts.projectRoot;
}
var platformManifestJson = path.join(platformProjPath, 'www/manifest.json');
if (!fs.existsSync(platformManifestJson)) {
return;
}
fs.readFile(platformManifestJson, 'utf8', function (err, platformJson) {
if (err) throw err; // we'll not consider error handling for now
var platformManifest = JSON.parse(platformJson);
var pluginManifestPath = path.join(
context.opts.projectRoot,
'plugins/@havesource/cordova-plugin-push/src/browser/manifest.json'
);
fs.readFile(pluginManifestPath, 'utf8', function (err, pluginJson) {
if (err) throw err; // we'll not consider error handling for now
var pluginManifest = JSON.parse(pluginJson);
platformManifest.gcm_sender_id = pluginManifest.gcm_sender_id;
fs.writeFile(
platformManifestJson,
JSON.stringify(platformManifest),
function (err) {
if (err) {
return console.log(err);
}
console.log('Manifest updated with push sender ID');
}
);
});
});
};
module.exports = function (context) {
console.log('Updating appxmanifests with ToastCapable=true ...');
var path = require('path');
var fs = require('fs');
var platformProjPath = path.join(context.opts.projectRoot, 'platforms/windows');
if (!fs.existsSync(platformProjPath)) {
platformProjPath = context.opts.projectRoot;
}
var AppxManifest = require(path.join(platformProjPath, 'cordova/lib/AppxManifest'));
['package.phone.appxmanifest', 'package.windows.appxmanifest'].forEach(function (manifestPath) {
var manifest = AppxManifest.get(path.join(platformProjPath, manifestPath));
manifest.getVisualElements().setToastCapable(true);
manifest.write();
});
};
{
"_from": "git+https://github.com/havesource/cordova-plugin-push.git#master",
"_id": "@havesource/cordova-plugin-push@4.0.0-dev.0",
"_inBundle": false,
"_integrity": "",
"_location": "/@havesource/cordova-plugin-push",
"_phantomChildren": {},
"_requested": {
"type": "git",
"raw": "https://github.com/havesource/cordova-plugin-push#master",
"rawSpec": "https://github.com/havesource/cordova-plugin-push#master",
"saveSpec": "git+https://github.com/havesource/cordova-plugin-push.git#master",
"fetchSpec": "https://github.com/havesource/cordova-plugin-push.git",
"gitCommittish": "master"
},
"_requiredBy": [
"#USER",
"/"
],
"_resolved": "git+https://github.com/havesource/cordova-plugin-push.git#c3fb5b894afe17a05e21be135961f5831bafb1e0",
"_spec": "https://github.com/havesource/cordova-plugin-push#master",
"_where": "/Users/n5648/Assorted Project/GerSg3030R3S4-CordovaAndroid11",
"author": {
"name": "Erisu"
},
"bugs": {
"url": "https://github.com/havesource/cordova-plugin-push/issues"
},
"bundleDependencies": false,
"cordova": {
"id": "@havesource/cordova-plugin-push",
"platforms": [
"ios",
"android",
"windows",
"browser"
]
},
"deprecated": false,
"description": "Register and receive push notifications.",
"devDependencies": {
"@babel/cli": "^7.15.4",
"@babel/core": "^7.15.5",
"@babel/eslint-parser": "^7.15.4",
"@babel/preset-env": "^7.15.6",
"@cordova/eslint-config": "^4.0.0",
"babel-plugin-add-header-comment": "^1.0.3",
"fs-extra": "^10.0.0",
"jasmine": "^3.9.0",
"nodemon": "^2.0.12",
"nopt": "^5.0.0",
"xml2js": "^0.4.23"
},
"engines": {
"cordovaDependencies": {
"1.0.0": {
"cordova": ">=10.0.0",
"cordova-android": ">=8.0.0",
"cordova-ios": ">=5.1.1"
},
"2.0.0": {
"cordova": ">=10.0.0",
"cordova-android": ">=8.0.0",
"cordova-ios": ">=6.0.0"
},
"3.0.0": {
"cordova": ">=10.0.0",
"cordova-android": ">=9.0.0",
"cordova-ios": ">=6.0.0"
}
}
},
"homepage": "https://github.com/havesource/cordova-plugin-push#readme",
"keywords": [
"ecosystem:cordova",
"cordova-ios",
"cordova-android",
"cordova-windows",
"cordova-browser"
],
"license": "MIT",
"name": "@havesource/cordova-plugin-push",
"repository": {
"type": "git",
"url": "git+https://github.com/havesource/cordova-plugin-push.git"
},
"scripts": {
"build": "babel src/js --out-dir www",
"build:watch": "nodemon -w ./src/js -e js -x npm run build",
"jasmine": "jasmine --config=spec/unit.json",
"lint": "eslint .",
"lint:fix": "npm run lint -- --fix",
"precommit-msg": "echo 'Pre-commit checks...' && exit 0",
"test": "npm run build && npm run lint && npm run jasmine"
},
"types": "./types/index.d.ts",
"version": "4.0.0-dev.0"
}
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="@havesource/cordova-plugin-push" version="4.0.0-dev.0">
<name>Cordova Push Plugin</name>
<description>Enable receiving push notifications on Android, iOS and Windows devices. Android uses Firebase Cloud Messaging. iOS uses Apple APNS Notifications. Windows uses Microsoft WNS Notifications.</description>
<license>MIT</license>
<js-module src="www/push.js" name="PushNotification">
<clobbers target="PushNotification"/>
</js-module>
<engines>
<engine name="cordova" version=">=10.0.0"/>
<engine name="cordova-android" version=">=9.0.0"/>
<engine name="cordova-ios" version=">=6.0.0"/>
</engines>
<platform name="android">
<hook type="before_compile" src="hooks/android/beforeCompile.js"/>
<config-file target="res/xml/config.xml" parent="/*">
<feature name="PushNotification">
<param name="android-package" value="com.adobe.phonegap.push.PushPlugin"/>
</feature>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="${applicationId}.permission.PushHandlerActivity"/>
<permission android:name="${applicationId}.permission.PushHandlerActivity" android:protectionLevel="signature"></permission>
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<activity android:name="com.adobe.phonegap.push.PushHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.PushHandlerActivity"/>
<activity android:name="com.adobe.phonegap.push.BackgroundHandlerActivity" android:exported="true" android:permission="${applicationId}.permission.BackgroundHandlerActivity">
<intent-filter>
<action android:name="com.adobe.phonegap.push.background.MESSAGING_EVENT"/>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<receiver android:name="com.adobe.phonegap.push.BackgroundActionButtonHandler"/>
<receiver android:name="com.adobe.phonegap.push.PushDismissedHandler"/>
<service android:name="com.adobe.phonegap.push.FCMService" android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</config-file>
<config-file target="config.xml" parent="/*">
<preference name="AndroidXEnabled" value="true" />
<preference name="GradlePluginGoogleServicesEnabled" value="true" />
<preference name="GradlePluginGoogleServicesVersion" value="4.3.8" />
<preference name="GradlePluginKotlinEnabled" value="true" />
<preference name="GradlePluginKotlinVersion" value="1.5.20" />
</config-file>
<preference name="ANDROIDX_CORE_VERSION" default="1.6.+"/>
<preference name="FCM_VERSION" default="23.+"/>
<framework src="androidx.core:core:$ANDROIDX_CORE_VERSION" />
<framework src="me.leolin:ShortcutBadger:1.1.22@aar"/>
<framework src="com.google.firebase:firebase-messaging:$FCM_VERSION"/>
<source-file src="src/android/com/adobe/phonegap/push/FCMService.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushConstants.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushHandlerActivity.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/BackgroundHandlerActivity.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushPlugin.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/BackgroundActionButtonHandler.kt" target-dir="java/com/adobe/phonegap/push/"/>
<source-file src="src/android/com/adobe/phonegap/push/PushDismissedHandler.kt" target-dir="java/com/adobe/phonegap/push/"/>
</platform>
<platform name="browser">
<js-module src="www/browser/push.js" name="BrowserPush">
<clobbers target="PushNotification"/>
</js-module>
<asset src="src/browser/ServiceWorker.js" target="ServiceWorker.js"/>
<asset src="src/browser/manifest.json" target="manifest.json"/>
<hook type="after_prepare" src="hooks/browser/updateManifest.js"/>
</platform>
<platform name="ios">
<preference name="IOS_FIREBASE_MESSAGING_VERSION" default="~> 8.1.1"/>
<config-file target="config.xml" parent="/*">
<feature name="PushNotification">
<param name="ios-package" value="PushPlugin"/>
</feature>
</config-file>
<config-file target="*-Info.plist" parent="UIBackgroundModes">
<array>
<string>remote-notification</string>
</array>
</config-file>
<config-file target="*-Debug.plist" parent="aps-environment">
<string>development</string>
</config-file>
<config-file target="*-Release.plist" parent="aps-environment">
<string>production</string>
</config-file>
<source-file src="src/ios/AppDelegate+notification.m"/>
<source-file src="src/ios/PushPlugin.m"/>
<header-file src="src/ios/AppDelegate+notification.h"/>
<header-file src="src/ios/PushPlugin.h"/>
<framework src="PushKit.framework"/>
<podspec>
<config>
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="Firebase/Messaging" spec="$IOS_FIREBASE_MESSAGING_VERSION" />
</pods>
</podspec>
</platform>
<platform name="windows">
<hook type="after_plugin_install" src="hooks/windows/setToastCapable.js"/>
<js-module src="src/windows/PushPluginProxy.js" name="PushPlugin">
<runs/>
</js-module>
<config-file target="config.xml" parent="/*">
<preference name="WindowsToastCapable" value="true"/>
</config-file>
</platform>
</plugin>
package com.adobe.phonegap.push
import android.annotation.SuppressLint
import android.app.NotificationManager
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
import androidx.core.app.RemoteInput
/**
* Background Action Button Handler
*/
@Suppress("HardCodedStringLiteral")
@SuppressLint("LongLogTag", "LogConditional")
class BackgroundActionButtonHandler : BroadcastReceiver() {
companion object {
private const val TAG: String = "${PushPlugin.PREFIX_TAG} (BackgroundActionButtonHandler)"
}
/**
* @param context
* @param intent
*/
override fun onReceive(context: Context, intent: Intent) {
val notId = intent.getIntExtra(PushConstants.NOT_ID, 0)
Log.d(TAG, "Not ID: $notId")
val notificationManager =
context.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(FCMService.getAppName(context), notId)
intent.extras?.let { extras ->
Log.d(TAG, "Intent Extras: $extras")
extras.getBundle(PushConstants.PUSH_BUNDLE)?.apply {
putBoolean(PushConstants.FOREGROUND, false)
putBoolean(PushConstants.COLDSTART, false)
putString(
PushConstants.ACTION_CALLBACK,
extras.getString(PushConstants.CALLBACK)
)
RemoteInput.getResultsFromIntent(intent)?.let { remoteInputResults ->
val results = remoteInputResults.getCharSequence(PushConstants.INLINE_REPLY).toString()
Log.d(TAG, "Inline Reply: $results")
putString(PushConstants.INLINE_REPLY, results)
}
}
PushPlugin.sendExtras(extras)
}
}
}
package com.adobe.phonegap.push
import android.annotation.SuppressLint
import android.app.Activity
import android.app.NotificationManager
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.core.app.RemoteInput
/**
* Background Handler Activity
*/
@Suppress("HardCodedStringLiteral")
@SuppressLint("LongLogTag", "LogConditional")
class BackgroundHandlerActivity : Activity() {
companion object {
private const val TAG: String = "${PushPlugin.PREFIX_TAG} (BackgroundHandlerActivity)"
}
/**
* This activity will be started if the user touches a notification that we own.
* We send it's data off to the push plugin for processing.
* If needed, we boot up the main activity to kickstart the application.
*
* @param savedInstanceState
*
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.v(TAG, "onCreate")
intent.extras?.let { extras ->
val notId = extras.getInt(PushConstants.NOT_ID, 0)
val callback = extras.getString(PushConstants.CALLBACK)
val startOnBackground = extras.getBoolean(PushConstants.START_IN_BACKGROUND, false)
val dismissed = extras.getBoolean(PushConstants.DISMISSED, false)
Log.d(TAG, "Not ID: $notId")
Log.d(TAG, "Callback: $callback")
Log.d(TAG, "Start In Background: $startOnBackground")
Log.d(TAG, "Dismissed: $dismissed")
FCMService().setNotification(notId, "")
if (!startOnBackground) {
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(FCMService.getAppName(this), notId)
}
processPushBundle()
finish()
if (!dismissed) {
// Tap the notification, app should start.
if (!PushPlugin.isActive) {
forceMainActivityReload(false)
} else {
forceMainActivityReload(true)
}
}
}
}
private fun processPushBundle() {
/*
* Takes the pushBundle extras from the intent,
* and sends it through to the PushPlugin for processing.
*/
intent.extras?.let { extras ->
var originalExtras = extras.getBundle(PushConstants.PUSH_BUNDLE)
if (originalExtras == null) {
originalExtras = extras
originalExtras.remove(PushConstants.FROM)
originalExtras.remove(PushConstants.MESSAGE_ID)
originalExtras.remove(PushConstants.COLLAPSE_KEY)
}
originalExtras.putBoolean(PushConstants.FOREGROUND, false)
originalExtras.putBoolean(PushConstants.COLDSTART, !PushPlugin.isActive)
originalExtras.putBoolean(PushConstants.DISMISSED, extras.getBoolean(PushConstants.DISMISSED))
originalExtras.putString(
PushConstants.ACTION_CALLBACK,
extras.getString(PushConstants.CALLBACK)
)
originalExtras.remove(PushConstants.NO_CACHE)
RemoteInput.getResultsFromIntent(intent)?.apply {
val reply = getCharSequence(PushConstants.INLINE_REPLY).toString()
Log.d(TAG, "Inline Reply: $reply")
originalExtras.putString(PushConstants.INLINE_REPLY, reply)
}
PushPlugin.sendExtras(originalExtras)
}
}
private fun forceMainActivityReload(startOnBackground: Boolean) {
/*
* Forces the main activity to re-launch if it's unloaded.
*/
val launchIntent = packageManager.getLaunchIntentForPackage(applicationContext.packageName)
intent.extras?.let { extras ->
launchIntent?.apply {
extras.getBundle(PushConstants.PUSH_BUNDLE)?.let { originalExtras ->
putExtras(originalExtras)
}
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
addFlags(Intent.FLAG_FROM_BACKGROUND)
putExtra(PushConstants.START_IN_BACKGROUND, startOnBackground)
}
}
startActivity(launchIntent)
}
/**
*
*/
override fun onResume() {
super.onResume()
val notificationManager = this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancelAll()
}
}
This diff is collapsed.
package com.adobe.phonegap.push
/**
* Push Constants
*
* @todo add docs about each constant.
*/
@Suppress("HardCodedStringLiteral")
object PushConstants {
const val COM_ADOBE_PHONEGAP_PUSH: String = "com.adobe.phonegap.push"
const val REGISTRATION_ID: String = "registrationId"
const val REGISTRATION_TYPE: String = "registrationType"
const val FOREGROUND: String = "foreground"
const val TITLE: String = "title"
const val NOT_ID: String = "notId"
const val PUSH_BUNDLE: String = "pushBundle"
const val ICON: String = "icon"
const val ICON_COLOR: String = "iconColor"
const val SOUND: String = "sound"
const val SOUND_DEFAULT: String = "default"
const val SOUND_RINGTONE: String = "ringtone"
const val VIBRATE: String = "vibrate"
const val ACTIONS: String = "actions"
const val CALLBACK: String = "callback"
const val ACTION_CALLBACK: String = "actionCallback"
const val DRAWABLE: String = "drawable"
const val MSGCNT: String = "msgcnt"
const val VIBRATION_PATTERN: String = "vibrationPattern"
const val STYLE: String = "style"
const val SUMMARY_TEXT: String = "summaryText"
const val PICTURE: String = "picture"
const val GCM_N: String = "gcm.n."
const val GCM_NOTIFICATION: String = "gcm.notification"
const val GCM_NOTIFICATION_BODY: String = "gcm.notification.body"
const val UA_PREFIX: String = "com.urbanairship.push"
const val PARSE_COM_DATA: String = "data"
const val ALERT: String = "alert"
const val MESSAGE: String = "message"
const val BODY: String = "body"
const val SOUNDNAME: String = "soundname"
const val COLOR: String = "color"
const val LED_COLOR: String = "ledColor"
const val PRIORITY: String = "priority"
const val IMAGE: String = "image"
const val STYLE_INBOX: String = "inbox"
const val STYLE_PICTURE: String = "picture"
const val STYLE_TEXT: String = "text"
const val BADGE: String = "badge"
const val INITIALIZE: String = "init"
const val SUBSCRIBE: String = "subscribe"
const val UNSUBSCRIBE: String = "unsubscribe"
const val UNREGISTER: String = "unregister"
const val EXIT: String = "exit"
const val FINISH: String = "finish"
const val HAS_PERMISSION: String = "hasPermission"
const val ANDROID: String = "android"
const val SENDER_ID: String = "senderID"
const val CLEAR_BADGE: String = "clearBadge"
const val CLEAR_NOTIFICATIONS: String = "clearNotifications"
const val COLDSTART: String = "coldstart"
const val ADDITIONAL_DATA: String = "additionalData"
const val COUNT: String = "count"
const val FROM: String = "from"
const val COLLAPSE_KEY: String = "collapse_key"
const val FORCE_SHOW: String = "forceShow"
const val FCM: String = "FCM"
const val CONTENT_AVAILABLE: String = "content-available"
const val TOPICS: String = "topics"
const val SET_APPLICATION_ICON_BADGE_NUMBER: String = "setApplicationIconBadgeNumber"
const val GET_APPLICATION_ICON_BADGE_NUMBER: String = "getApplicationIconBadgeNumber"
const val CLEAR_ALL_NOTIFICATIONS: String = "clearAllNotifications"
const val VISIBILITY: String = "visibility"
const val INLINE_REPLY: String = "inlineReply"
const val INLINE_REPLY_LABEL: String = "replyLabel"
const val LOC_KEY: String = "locKey"
const val LOC_DATA: String = "locData"
const val TWILIO_BODY: String = "twi_body"
const val TWILIO_TITLE: String = "twi_title"
const val TWILIO_SOUND: String = "twi_sound"
const val AWS_PINPOINT_BODY: String = "pinpoint.notification.body"
const val AWS_PINPOINT_PICTURE: String = "pinpoint.notification.imageUrl"
const val AWS_PINPOINT_PREFIX: String = "pinpoint.notification"
const val MP_MESSAGE: String = "mp_message"
const val START_IN_BACKGROUND: String = "cdvStartInBackground"
const val FORCE_START: String = "force-start"
const val MESSAGE_KEY: String = "messageKey"
const val TITLE_KEY: String = "titleKey"
const val NO_CACHE: String = "no-cache"
const val DISMISSED: String = "dismissed"
const val IMAGE_TYPE: String = "image-type"
const val IMAGE_TYPE_SQUARE: String = "square"
const val IMAGE_TYPE_CIRCLE: String = "circle"
const val SUBJECT: String = "subject"
const val GOOGLE_APP_ID: String = "google_app_id"
const val GCM_DEFAULT_SENDER_ID: String = "gcm_defaultSenderId"
const val PUSH_DISMISSED: String = "push_dismissed"
const val DEFAULT_CHANNEL_ID: String = "PushPluginChannel"
const val CHANNELS: String = "channels"
const val CHANNEL_ID: String = "id"
const val CHANNEL_DESCRIPTION: String = "description"
const val CHANNEL_IMPORTANCE: String = "importance"
const val CHANNEL_LIGHT_COLOR: String = "lightColor"
const val CHANNEL_VIBRATION: String = "vibration"
const val ANDROID_CHANNEL_ID: String = "android_channel_id"
const val CHANNEL_STATE: String = "state"
const val CREATE_CHANNEL: String = "createChannel"
const val DELETE_CHANNEL: String = "deleteChannel"
const val ONGOING: String = "ongoing"
const val LIST_CHANNELS: String = "listChannels"
const val CLEAR_NOTIFICATION: String = "clearNotification"
const val MESSAGE_ID: String = "google.message_id"
const val IS_ENABLED: String = "isEnabled"
}
package com.adobe.phonegap.push
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.util.Log
/**
*
*/
@Suppress("HardCodedStringLiteral")
@SuppressLint("LongLogTag")
class PushDismissedHandler : BroadcastReceiver() {
companion object {
private const val TAG: String = "${PushPlugin.PREFIX_TAG} (PushDismissedHandler)"
}
/**
* @param context
* @param intent
*/
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == PushConstants.PUSH_DISMISSED) {
val notID = intent.getIntExtra(PushConstants.NOT_ID, 0)
Log.d(TAG, "not id = $notID")
FCMService().setNotification(notID, "")
}
}
}
package com.adobe.phonegap.push
import android.annotation.SuppressLint
import android.app.Activity
import android.app.NotificationManager
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.util.Log
import androidx.core.app.RemoteInput
/**
* Push Handler Activity
*/
@Suppress("HardCodedStringLiteral")
@SuppressLint("LongLogTag", "LogConditional")
class PushHandlerActivity : Activity() {
companion object {
private const val TAG: String = "${PushPlugin.PREFIX_TAG} (PushHandlerActivity)"
}
/**
* this activity will be started if the user touches a notification that we own.
* We send it's data off to the push plugin for processing.
* If needed, we boot up the main activity to kickstart the application.
*
* @param savedInstanceState
*
* @see android.app.Activity#onCreate(android.os.Bundle)
*/
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.v(TAG, "onCreate")
intent.extras?.let { extras ->
val notId = extras.getInt(PushConstants.NOT_ID, 0)
val callback = extras.getString(PushConstants.CALLBACK)
var foreground = extras.getBoolean(PushConstants.FOREGROUND, true)
val startOnBackground = extras.getBoolean(PushConstants.START_IN_BACKGROUND, false)
val dismissed = extras.getBoolean(PushConstants.DISMISSED, false)
FCMService().setNotification(notId, "")
if (!startOnBackground) {
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancel(FCMService.getAppName(this), notId)
}
val notHaveInlineReply = processPushBundle()
if (notHaveInlineReply && Build.VERSION.SDK_INT < Build.VERSION_CODES.N && !startOnBackground) {
foreground = true
}
Log.d(TAG, "Not ID: $notId")
Log.d(TAG, "Callback: $callback")
Log.d(TAG, "Foreground: $foreground")
Log.d(TAG, "Start On Background: $startOnBackground")
Log.d(TAG, "Dismissed: $dismissed")
finish()
if (!dismissed) {
Log.d(TAG, "Is Push Plugin Active: ${PushPlugin.isActive}")
if (!PushPlugin.isActive && foreground && notHaveInlineReply) {
Log.d(TAG, "Force Main Activity Reload: Start on Background = False")
forceMainActivityReload(false)
} else if (startOnBackground) {
Log.d(TAG, "Force Main Activity Reload: Start on Background = True")
forceMainActivityReload(true)
} else {
Log.d(TAG, "Don't Want Main Activity")
}
}
}
}
private fun processPushBundle(): Boolean {
/*
* Takes the pushBundle extras from the intent,
* and sends it through to the PushPlugin for processing.
*/
return intent.extras?.let { extras ->
var notHaveInlineReply = true
extras.getBundle(PushConstants.PUSH_BUNDLE)?.apply {
putBoolean(PushConstants.FOREGROUND, false)
putBoolean(PushConstants.COLDSTART, !PushPlugin.isActive)
putBoolean(PushConstants.DISMISSED, extras.getBoolean(PushConstants.DISMISSED))
putString(
PushConstants.ACTION_CALLBACK,
extras.getString(PushConstants.CALLBACK)
)
remove(PushConstants.NO_CACHE)
RemoteInput.getResultsFromIntent(intent)?.let { results ->
val reply = results.getCharSequence(PushConstants.INLINE_REPLY).toString()
Log.d(TAG, "Inline Reply: $reply")
putString(PushConstants.INLINE_REPLY, reply)
notHaveInlineReply = false
}
PushPlugin.sendExtras(this)
}
return notHaveInlineReply
} ?: true
}
private fun forceMainActivityReload(startOnBackground: Boolean) {
/*
* Forces the main activity to re-launch if it's unloaded.
*/
val launchIntent = packageManager.getLaunchIntentForPackage(applicationContext.packageName)
intent.extras?.let { extras ->
launchIntent?.apply {
extras.getBundle(PushConstants.PUSH_BUNDLE)?.apply {
putExtras(this)
}
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
addFlags(Intent.FLAG_FROM_BACKGROUND)
putExtra(PushConstants.START_IN_BACKGROUND, startOnBackground)
}
}
startActivity(launchIntent)
}
/**
* On Resuming of Activity
*/
override fun onResume() {
super.onResume()
val notificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager
notificationManager.cancelAll()
}
}
This diff is collapsed.
var messageChannel;
self.addEventListener('install', function (event) {
self.skipWaiting();
});
self.addEventListener('push', function (event) {
// parse incoming message
var obj = {};
var pushData = {
image: 'https://avatars1.githubusercontent.com/u/60365?v=3&s=200',
additionalData: {}
};
if (event.data) {
obj = event.data.json();
}
console.log(obj);
// convert to push plugin API
for (var key in obj) {
if (key === 'title') {
pushData.title = obj[key];
} else if (key === 'message' || key === 'body') {
pushData.message = obj[key];
} else if (key === 'count' || key === 'msgcnt' || key === 'badge') {
pushData.count = obj[key];
} else if (key === 'sound' || key === 'soundname') {
pushData.sound = obj[key];
} else if (key === 'image') {
pushData.image = obj[key];
} else {
pushData.additionalData[key] = obj[key];
}
}
event.waitUntil(
self.registration.showNotification(pushData.title, {
body: pushData.message,
icon: pushData.image,
tag: 'simple-push-demo-notification-tag'
})
);
messageChannel.ports[0].postMessage(pushData);
});
self.addEventListener('message', function (event) {
messageChannel = event;
});
{
"name": "Push Demo",
"gcm_sender_id": "996231231186"
}
//
// AppDelegate+notification.h
// pushtest
//
// Created by Robert Easterday on 10/26/12.
//
//
#import "AppDelegate.h"
@import UserNotifications;
extern NSString *const pushPluginApplicationDidBecomeActiveNotification;
@interface AppDelegate (notification) <UNUserNotificationCenterDelegate>
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:( void (^)(UIBackgroundFetchResult))completionHandler;
- (void)pushPluginOnApplicationDidBecomeActive:(UIApplication *)application;
- (void)checkUserHasRemoteNotificationsEnabledWithCompletionHandler:(nonnull void (^)(BOOL))completionHandler;
- (id) getCommandInstance:(NSString*)className;
@property (nonatomic, retain) NSDictionary *launchNotification;
@property (nonatomic, retain) NSNumber *coldstart;
@end
//
// AppDelegate+notification.m
// pushtest
//
// Created by Robert Easterday on 10/26/12.
//
//
#import "AppDelegate+notification.h"
#import "PushPlugin.h"
#import <objc/runtime.h>
static char launchNotificationKey;
static char coldstartKey;
NSString *const pushPluginApplicationDidBecomeActiveNotification = @"pushPluginApplicationDidBecomeActiveNotification";
@implementation AppDelegate (notification)
- (id) getCommandInstance:(NSString*)className
{
return [self.viewController getCommandInstance:className];
}
// its dangerous to override a method from within a category.
// Instead we will use method swizzling. we set this up in the load call.
+ (void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(init);
SEL swizzledSelector = @selector(pushPluginSwizzledInit);
Method original = class_getInstanceMethod(class, originalSelector);
Method swizzled = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzled),
method_getTypeEncoding(swizzled));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(original),
method_getTypeEncoding(original));
} else {
method_exchangeImplementations(original, swizzled);
}
});
}
- (AppDelegate *)pushPluginSwizzledInit
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[[NSNotificationCenter defaultCenter]addObserver:self
selector:@selector(pushPluginOnApplicationDidBecomeActive:)
name:UIApplicationDidBecomeActiveNotification
object:nil];
// This actually calls the original init method over in AppDelegate. Equivilent to calling super
// on an overrided method, this is not recursive, although it appears that way. neat huh?
return [self pushPluginSwizzledInit];
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
[pushHandler didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
[pushHandler didFailToRegisterForRemoteNotificationsWithError:error];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
NSLog(@"didReceiveNotification with fetchCompletionHandler");
// app is in the background or inactive, so only call notification callback if this is a silent push
if (application.applicationState != UIApplicationStateActive) {
NSLog(@"app in-active");
// do some convoluted logic to find out if this should be a silent push.
long silent = 0;
id aps = [userInfo objectForKey:@"aps"];
id contentAvailable = [aps objectForKey:@"content-available"];
if ([contentAvailable isKindOfClass:[NSString class]] && [contentAvailable isEqualToString:@"1"]) {
silent = 1;
} else if ([contentAvailable isKindOfClass:[NSNumber class]]) {
silent = [contentAvailable integerValue];
}
if (silent == 1) {
NSLog(@"this should be a silent push");
void (^safeHandler)(UIBackgroundFetchResult) = ^(UIBackgroundFetchResult result){
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler(result);
});
};
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
if (pushHandler.handlerObj == nil) {
pushHandler.handlerObj = [NSMutableDictionary dictionaryWithCapacity:2];
}
id notId = [userInfo objectForKey:@"notId"];
if (notId != nil) {
NSLog(@"Push Plugin notId %@", notId);
[pushHandler.handlerObj setObject:safeHandler forKey:notId];
} else {
NSLog(@"Push Plugin notId handler");
[pushHandler.handlerObj setObject:safeHandler forKey:@"handler"];
}
pushHandler.notificationMessage = userInfo;
pushHandler.isInline = NO;
[pushHandler notificationReceived];
} else {
NSLog(@"just put it in the shade");
//save it for later
self.launchNotification = userInfo;
completionHandler(UIBackgroundFetchResultNewData);
}
} else {
completionHandler(UIBackgroundFetchResultNoData);
}
}
- (void)checkUserHasRemoteNotificationsEnabledWithCompletionHandler:(nonnull void (^)(BOOL))completionHandler
{
[[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
switch (settings.authorizationStatus)
{
case UNAuthorizationStatusDenied:
case UNAuthorizationStatusNotDetermined:
completionHandler(NO);
break;
case UNAuthorizationStatusAuthorized:
completionHandler(YES);
break;
}
}];
}
- (void)pushPluginOnApplicationDidBecomeActive:(NSNotification *)notification {
NSLog(@"active");
NSString *firstLaunchKey = @"firstLaunchKey";
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"phonegap-plugin-push"];
if (![defaults boolForKey:firstLaunchKey]) {
NSLog(@"application first launch: remove badge icon number");
[defaults setBool:YES forKey:firstLaunchKey];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
UIApplication *application = notification.object;
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
if (pushHandler.clearBadge) {
NSLog(@"PushPlugin clearing badge");
//zero badge
application.applicationIconBadgeNumber = 0;
} else {
NSLog(@"PushPlugin skip clear badge");
}
if (self.launchNotification) {
pushHandler.isInline = NO;
pushHandler.coldstart = [self.coldstart boolValue];
pushHandler.notificationMessage = self.launchNotification;
self.launchNotification = nil;
self.coldstart = [NSNumber numberWithBool:NO];
[pushHandler performSelectorOnMainThread:@selector(notificationReceived) withObject:pushHandler waitUntilDone:NO];
}
[[NSNotificationCenter defaultCenter] postNotificationName:pushPluginApplicationDidBecomeActiveNotification object:nil];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler
{
NSLog( @"NotificationCenter Handle push from foreground" );
// custom code to handle push while app is in the foreground
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
pushHandler.notificationMessage = notification.request.content.userInfo;
pushHandler.isInline = YES;
// [pushHandler notificationReceived];
// completionHandler(UNNotificationPresentationOptionNone);
completionHandler(UNNotificationPresentationOptionAlert);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)(void))completionHandler
{
NSLog(@"Push Plugin didReceiveNotificationResponse: actionIdentifier %@, notification: %@", response.actionIdentifier,
response.notification.request.content.userInfo);
NSMutableDictionary *userInfo = [response.notification.request.content.userInfo mutableCopy];
[userInfo setObject:response.actionIdentifier forKey:@"actionCallback"];
NSLog(@"Push Plugin userInfo %@", userInfo);
switch ([UIApplication sharedApplication].applicationState) {
case UIApplicationStateActive:
{
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
pushHandler.notificationMessage = userInfo;
pushHandler.isInline = YES;
[pushHandler notificationReceived];
completionHandler();
break;
}
case UIApplicationStateInactive:
{
NSLog(@"coldstart");
self.launchNotification = response.notification.request.content.userInfo;
self.coldstart = [NSNumber numberWithBool:YES];
break;
}
case UIApplicationStateBackground:
{
void (^safeHandler)(void) = ^(void){
dispatch_async(dispatch_get_main_queue(), ^{
completionHandler();
});
};
PushPlugin *pushHandler = [self getCommandInstance:@"PushNotification"];
if (pushHandler.handlerObj == nil) {
pushHandler.handlerObj = [NSMutableDictionary dictionaryWithCapacity:2];
}
id notId = [userInfo objectForKey:@"notId"];
if (notId != nil) {
NSLog(@"Push Plugin notId %@", notId);
[pushHandler.handlerObj setObject:safeHandler forKey:notId];
} else {
NSLog(@"Push Plugin notId handler");
[pushHandler.handlerObj setObject:safeHandler forKey:@"handler"];
}
pushHandler.notificationMessage = userInfo;
pushHandler.isInline = NO;
[pushHandler performSelectorOnMainThread:@selector(notificationReceived) withObject:pushHandler waitUntilDone:NO];
}
}
}
// The accessors use an Associative Reference since you can't define a iVar in a category
// http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/objectivec/Chapters/ocAssociativeReferences.html
- (NSMutableArray *)launchNotification
{
return objc_getAssociatedObject(self, &launchNotificationKey);
}
- (void)setLaunchNotification:(NSDictionary *)aDictionary
{
objc_setAssociatedObject(self, &launchNotificationKey, aDictionary, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (NSNumber *)coldstart
{
return objc_getAssociatedObject(self, &coldstartKey);
}
- (void)setColdstart:(NSNumber *)aNumber
{
objc_setAssociatedObject(self, &coldstartKey, aNumber, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}
- (void)dealloc
{
self.launchNotification = nil; // clear the association and release the object
self.coldstart = nil;
}
@end
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment