How to completely stop or start receiving push messages - infobip/mobile-messaging-sdk-ios GitHub Wiki

Important

Push registration is enabled by default, that means that you don't need to use method for enabling it. Disabled push registration is the one that will completely stop receiving push notifications. Disabling push registration is needed to be used only if you want to opt out of receiving notifications. If you just don't want notifications to be displayed in the notification center, you can send silent campaigns.

Disabling the push registration

In order to disable the current user from receiving push messages, you have to change his push registration status. Here are the steps:

  1. Start MobileMessaging SDK in a way it's described in the Quick Start Guide if it is not started yet.
  2. Once the SDK has been successfully initialized and started, do the following:
if let installation = MobileMessaging.getInstallation() {
    installation.isPushRegistrationEnabled = false

    do {
        try await MobileMessaging.saveInstallation(installation)
    } catch {
        // handle error
        print("Error: \(error)")
    }
}
expand to see completion block version

if let installation = MobileMessaging.getInstallation() {
    installation.isPushRegistrationEnabled = false

    MobileMessaging.saveInstallation(installation, completion: { error in
        if let error = error {
            // handle error
        }
    })
}

Enabling the push registration

In order to enable current user back to receiving push messages, you enable user's push registration:

  1. Start MobileMessaging SDK in a way it's described in the Quick Start Guide if it is not started yet.
  2. Once the SDK has been successfully initialized and started, do the following:
if let installation = MobileMessaging.getInstallation() {
    installation.isPushRegistrationEnabled = true

    do {
        try await MobileMessaging.saveInstallation(installation)
    } catch {
        // handle error
        print("Error: \(error)")
    }
}
expand to see completion block version

if let installation = MobileMessaging.getInstallation() {
    installation.isPushRegistrationEnabled = true

    MobileMessaging.saveInstallation(installation, completion: { error in
        if let error = error {
            // handle error
        }
    })
}

Retrieving the current push registration status

In order to get the current registration status, use the following code:

let isPushRegistrationEnabled = MobileMessaging.getInstallation().isPushRegistrationEnabled
⚠️ **GitHub.com Fallback** ⚠️