iOS Native SDK

Comprehensive reference of iZooto's SDK methods for iOS.

📘

Just starting with iOS?

Check out our iOS SDK Integration guide.

Parameter

Data Type

Description

Debug

getToken

Key

Will provide you the subscription token for the current device.

Initialise

initialisation

Method

Initialise iZooto

provisionalCheck

Key

Allows your app users to subscribe to receiving notifications directly without any opt-in consent.
Notifications in this case would be delivered silently.

User Permission

checkNotificationEnable

Method

If notifications are disabled by the user, this method can be used to ask user to change his notification permissions with a native iOS alert.

setSubscription

Method

Disables iZooto from sending notifications to the current device.

Appearance

setBadgeCount

Method

Customize the badge count displayed on the app icon.

Sound

setNotificationSound

Method

Customize the sound that gets played whenever a notification is received on the device.

Notification Handler

onNotificationReceived

Handler

Called when a notification is received by a device.

onNotificationView

Handler

Called when the notification is clicked by the user.

Debug

getToken

Key

This method will return the subscription token of the current device. Token would only be visible once the user has accepted the Push Notification Opt-In prompt.

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
                
          iZooto.getToken(deviceToken: deviceToken)
          print(deviceToken)
       
    }


Initialize

provisionalCheck

Key

This key makes use of Apple's Provisional Authentication where users are not presented with an opt-in prompt to "Allow" push notifications. Rather they are automatically considered as a subscriber when the application is launched.
Subscribers in these cases would receive a silent notification with no alert, badge, or sound and the notification will directly be populated in the notification center.

Once the user receives a notification, the opt-in would be embedded inside the notification where the user can make an informed decision based on the content you push to them whether to keep receiving notifications as silent or change notification permission to be delivered prominently.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        iZooto.initialisation(izooto_id: "YOUR_APP_ID", application: application, provisioanlCheck: false)
        UNUserNotificationCenter.current().delegate = self
        iZooto.delegate = self
        return true
    }

User Permission

checkNotificationEnable

Method

If the user has not allowed for notifications initially, this method can be used to prompt users to change their notification permissions from Settings. In order to maximize the impact of this, it should be paired with proper UI and should only be triggered based on user activity.

Recommendation: Having a toggle in your App's UI is suggested to invoke this method.
On tapping "Take me there" users would be redirected taken to the System Settings for that particular application where they can enable notifications.

iZooto.checkNotificationEnable()

setSubscription

Method

Can be used to not deliver notifications to a specific device. This method does not officially subscribe or unsubscribe users from the app settings, it unsubscribes them from receiving a push from iZooto.
You can call this method with false to opt-out users from receiving notifications through iZooto. You can pass true later to opt users back into notifications.

iZooto.isSubscribe(isSubscribe:false)


Custom Badge Count

setBadgeCount

Method

Used to set a custom badge count to be displayed on the app icon on the device. By default, the notification count is set as incremental.

This can be modified to a static number by using the below method:

func applicationDidBecomeActive(_ application: UIApplication) {
  application.applicationIconBadgeNumber = 0
  iZooto.setBadgeCount(badgeNumber: 1)
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
  [iZooto setBadgeCountWithBadgeNumber:1];
  application.applicationIconBadgeNumber = 0;
}

If your project is built using SWIFT, you will have to make some additional changes in the SceneDelegate.swift file as below:

@available(iOS 13.0, *)
func sceneDidBecomeActive(_ scene: UIScene) {
  UIApplication.shared.applicationIconBadgeNumber = 0
  iZooto.setBadgeCount(badgeNumber: 1)
}

@available(iOS 13.0, *)
func sceneWillEnterForeground(_ scene: UIScene) {
  UIApplication.shared.applicationIconBadgeNumber = 0
  iZooto.setBadgeCount(badgeNumber: 1)
}

🚧

Pass 0 in the setBadgeCount method to default to an incremental value.



Sound

setNotificationSound

Method

Used to set a custom sound to the notifications when delivered on the device. The device's usual notification sound is played by default, which can be overridden to use a custom sound for your app.

The following line of code needs to be added in the NotificationService class:

bestAttemptContent.sound = UNNotificationSound(named: UNNotificationSoundName(rawValue: "Sound_File_Name_with_Extension"))
self.bestAttemptContent.sound = [NSString stringWithFormat:@"Sound_File_Name_with_Extension", self.bestAttemptContent.sound];

🚧

Points to Note

  • The notifications sound file should already be present in the project directory.
  • Supported file types are .mp3 and .wav.
  • The file name needs to be passed with the file extension.

Notification Handler

onNotificationReceived

Handler

Fires when a notification is received. It will be fired when your app is in focus or in the background.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, iZootoNotificationActionDelegate {

    func onNotificationReceived(payload: Aps) {

      // Returns the content of Notification Payload.
      print("Data",payload.alert?.title as Any)
    }
}

onNotificationView

Handler

Use to process an iZooto notification the user just tapped on.

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, iZootoNotificationActionDelegate {
    
        func onOpenActionHandler(action: String) {
            print("Data",action)
    }

Did this page help you?