To implement push notifications in our app we need to create a .p8 key file from developer.apple.com and setup the settings for the notification in the dashboard.
We also need to create a provisioning profile for the app because push notifications don't work with a wildcard provisioning profile.
In the MBurger dashboard under Settings > Info & Features you can see two fields that you will need to setup your app to receive push notifications from MBurger:
Push token
Project topic for push
The first one identifies your MBurger project and will be used to setup the service in your didFinishLaunchingWithOptions, the second one will be used to register the token of your device once you obtain one from APNS.
Then, create your own class extending FirebaseMessagingService (called FCMReceiver) which will be used to retrieve Firebase token and send it to MBurger Push and to receive and create notifications for your app:
publicclassFCMReceiverextendsFirebaseMessagingService {@OverridepublicvoidonNewToken(String token) { MBurgerPushTasks.sendToken(getApplicationContext(),getDeviceID(), token); }@OverridepublicvoidonMessageReceived(RemoteMessage remoteMessage) {Map<String,String> map =remoteMessage.getData();//The standard message is inside the “body” fieldString msg =map.get(“body”);if(map.containsKey(“custom”)) {String customJsonData =map.get(“custom”);if(customJsonData !=null){createNofitication(custom); } } }}
Remember to also add them also on your manifest.xml file:
Then as a last thing to do, register your users to a topic, which will be needed to target specific groups of users while sending push notifications.
For this example we would want to send push notifications about flash sales of our store (or important news about a celebrity), so we use the “flash_deals” topic or “flash_news”.