MBurger Headless CMS
User GuideCMS HeadlessEngagement Platform
  • 🍔MBurger Documentation🍔
  • 🔑 API
    • Introduction
      • Getting Started
      • Structure
    • Common Path
      • Basics
      • POST Bodies
      • POST Relations
      • Evaluating Responses
    • API Authentication
    • Project
    • Blocks
      • Get Blocks
      • Get Block
    • Sections
      • Get Sections
      • Get Section
      • Create Section
      • Update Section
      • Delete Section
    • Media
      • Get All Media
      • Upload Media
      • Get Media
      • Delete Media
    • Integrations / Extensions
      • Authentication Provider
        • Registration
        • Login
        • Logout
        • Get Profile
        • Update Profile
        • Delete Profile
        • Change Password
        • Forgot Password
      • Live Messages
        • Get All Live Messages
        • Send Live Message
        • Delete Live Message
      • In-App Subscriptions
        • InApp Subscription
        • Resume InApp Subscription
      • Shopify
        • Create a Shopify private app
        • Enable Shopify in MBurger
        • Collections Editor
      • Stripe
        • Create Customer
        • Get Cards
        • Create Card
        • Make Default
        • Delete Card
        • Subscription
        • Cancel Subscription
        • Resume Subscription
        • Payment
    • Going Deeper
      • Available Data Types (Elements)
  • 📱 Android SDK
    • Introduction
    • Installation
    • Initialization
    • Fetch for blocks
    • Fetch sections from blocks
    • Mapping to custom objects
    • Admin
      • Delete a Section/Media
      • Create a new Section
      • Update an existing Section
    • Auth
      • Register a new user
      • Authenticate a user
      • User profile
      • Edit profile
      • Other features
    • Proguard Rules
    • Plugins
    • Sample Apps
      • MBurger Explorer
      • MBurger Radio
    • MBurger Apps
  • 🍏 iOS SDK
    • Introduction
    • Installation
    • Initialization
    • Fetch the project
    • Fetch blocks
    • Fetch sections
    • Media
    • Encoding & Decoding
    • Serialization & Equality
    • Admin
      • Add/Edit a section
      • Delete a section
      • Upload media
      • Delete a media
    • Auth
      • Register a user
      • Authenticate a user
      • Retrieve user information
      • Update user profile
    • Plugins
    • Sample Apps
      • MBurger Explorer
      • MBurger Radio
    • MBurger Apps
  • 💻 PHP SDK
    • Installation & Configuration
    • How to use
    • Support & Feedback
    • License
  • ☕ JavaScript SDK
    • Introduction
    • Installation
    • Configuration
    • Methods Reference
    • Support & Feedback
    • License
  • 🔷Flutter SDK
    • Installation
    • Initialization
    • Fetch the project
    • Fetch blocks
    • Fetch sections
    • Media
    • Admin
      • Add/Edit a section
      • Delete a section
      • Upload a media
      • Delete a media
    • Auth
      • Register a user
      • Authenticate a user
      • Retrieve user information
      • Update user profile
  • ❓How to?
    • Basic interactions
      • Blocks
        • Get a Single Block
        • Get multiple Blocks
      • Sections
        • Get a single Section
        • Get Multiple Sections
        • Create a Section
        • Update a Section
        • Delete a Section
    • Advanced section retrieval
      • Filter sections
      • Obtain distance from a section
      • Manage locales and the fallback language
      • Get a section by SLUG
      • Obtain only sections with a defined relation
    • Advanced section creation
      • Create a section with a relation
      • Set the value of a checkbox element
      • Create a section with a multiple or dropdown element
      • Create a section with a SLUG
      • Create a section with SEO
      • Send or schedule a push when creating a section
    • Set the visibility of a section
    • Get images with various format
  • 👻 Sample App
    • Introduction
    • Create an MBurger project
    • Create Home, News and Gallery blocks
    • Create the project
    • Setup the SDK
    • Query the API for items
    • Map your objects from MBurger objects
    • Implement push notifications
    • Take a bite
Powered by GitBook
On this page

Was this helpful?

  1. Sample App

Implement push notifications

PreviousMap your objects from MBurger objectsNextTake a bite

Last updated 4 years ago

Was this helpful?

To implement push notifications in our app we need to create a .p8 key file from 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.

Add this to your AppDelegate:

import UserNotifications

...

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions
        launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        MBManager.shared().pushToken = “YOUR_TOKEN”

        …

        let userNotificationCenter = UNUserNotificationCenter.current()
        userNotificationCenter.delegate = self
        registerForPushNotifications()
}

...

// MARK: – Notifications

func registerForPushNotifications() {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, _) in
        guard granted else { return }
        self.getNotificationSettings()
    }
}

func getNotificationSettings() {
    UNUserNotificationCenter.current().getNotificationSettings { (settings) in
        guard settings.authorizationStatus == .authorized else { return }
        DispatchQueue.main.async {
            UIApplication.shared.registerForRemoteNotifications()
        }
    }
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    MumblePush.registerDevice(deviceToken: deviceToken, success: {
        let topics = [“TOPIC_ID”]
        MumblePush.register(toTopics: topics)
    })
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print(“Failed to register: \(error)“)
}

extension AppDelegate: UNUserNotificationCenterDelegate {
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                willPresent notification: UNNotification,
                                withCompletionHandler
        completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler(UNNotificationPresentationOptions.alert)
    }

    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler
        completionHandler: @escaping () -> Void) {
        completionHandler()
    }
}

You must create a Firebase project for your application, so that you’ll have the push server key to insert in your MBurger Push project.

This will generate a push API KEY.

com.google.firebase:firebase–core
com.google.firebase:firebase–messaging

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:

public class FCMReceiver extends FirebaseMessagingService {

@Override 
public void onNewToken(String token) { 
     MBurgerPushTasks.sendToken(getApplicationContext(), getDeviceID(), token); 
}

@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
     Map<String, String> map = remoteMessage.getData();

     //The standard message is inside the “body” field
     String 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:

<service android:name=“.FCMReceiver”>
   <intent-filter>
       <action android:name=“com.google.firebase.MESSAGING_EVENT” />
   </intent-filter>
</service>

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”.

JSONArray topics = new JSONArray();
topics.put(“flash_deals”); //or “flash_news”
MBurgerPushTasks.registerTopics(context, getDeviceID(), topics);

If you want more information about how push notifications work on iOS, visit the .

To create a new Firebase project, please reference documentation, then add these dependencies to your project at the latest version available:

👻
developer.apple.com
Apple official guide
this