- Install Node, Ionic, cordova and node_modules
$ npm install -g ionic $ npm install -g [email protected]
- Clone this repository
$ git clone https://github.com/TongZhangzt/Ionic2-push-notification.git $ cd Ionic2-push-notification $ npm install
- Install Phonegap Plugin, set you sender id
$ Cordova pulgin add phonegap-plugin-push --variable SENDER_ID="xxxxxx"
- Replace sender_id in app.component.js
Build and run in Android
$ ionic platform add android $ ionic run android
Build and run in ios
$ ionic platform add ios $ ionic build ios
In ios app, you need to run the xcode file in the platforms/ios folder with Xcode.
-
Replace the device token printed in console for push notifications in gcmService.js.
-
Run the server code to push notifications:
$ cd server $ npm install $ node gcmService
Go to localhost:3000/push to send a push notification