Is it possible to access push notification
content in ionic 2 and execute bunch of code when notification arrive or event fire
?
相关问题
- Angular RxJS mergeMap types
- void before promise syntax
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- Ignore Typescript errors in Webpack-dev-server
- How to update placeholder text in ng2-smart-table?
相关文章
- angular脚手架在ie9+下兼容问题
- angular 前端项目 build 报错 "Cannot find module 'le
- Cannot find module 'redux' 怎么解决?
- Angular Material Stepper causes mat-formfield to v
- After upgrade to Angular 9 cannot find variable in
- is there any difference between import { Observabl
- Suppress “Circular dependency detected” suppress w
- How can make folder with Firebase Cloud Functions
Yes it is, you'll need a plugin to this, i use the cordova-plugin-fcm.
In your
app.ts
you can do the followingInside was tapper you'll do your code.
Hope this helps.
I'd recommend using the cordova-plugin-firebase instead. You can take a look at this repo to see how to use that plugin.
Please notice that you'd need first to configure the firebase console, and donwload the .json / .plist files and add them to the root folder of your Ionic app. Then you can start using the plugin.
In the demo everything is done in the
app.component.ts
file, but I recommend creating aPushNotificationService
to keep everything organised.Please also notice that the demo uses topics features, so devices can subscribe to specific topics, and then we can use these topics to send notifications to some group of users (only android or ios, only a specific user, all users from the app...):
This is all the related code:
Also please notice, that the content of the notification sent will not be the same if the app is running in the foreground or if the app is closed when the notification arrives. In order to handle that, when sending a notification, add the
title
and thebody
in the Advanced options section