iOS Native SDK

Comprehensive reference of iZooto's SDK methods for iOS apps built with the Native framework.

📘

Just starting with iOS?

Check out our iOS SDK Integration guide.

ParameterData TypeDescription
Debug
getTokenKeyWill provide you the subscription token for the current device.
Initialise
initialisationMethodInitialise iZooto
provisionalCheckKeyAllows your app users to subscribe to receiving notifications directly without any opt-in consent.
Notifications in this case would be delivered silently.
User Permission
checkNotificationEnableMethodIf notifications are disabled by the user, this method can be used to ask user to change his notification permissions with a native iOS alert.
setSubscriptionMethodDisables iZooto from sending notifications to the current device.
Appearance
setBadgeCountMethodCustomize the badge count displayed on the app icon.
Sound
setNotificationSoundMethodCustomize the sound that gets played whenever a notification is received on the device.
Notification Handler
onNotificationReceivedHandlerCalled when a notification is received by a device.
onNotificationViewHandlerCalled when the notification is clicked by the user.

Debug

getToken

This method will return the subscription token of the current device. The 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)
}

Initialization

provisionalCheck

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

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 {
  // for setting
  let iZootoInitSettings = ["auto_prompt": true, "nativeWebview": true, "provisionalAuthorization": Yes]
  iZooto.initialisation(izooto_id: "<iZooto_app_id>", application: application, iZootoInitSettings:iZootoInitSettings)
  
  UNUserNotificationCenter.current().delegate = self
  
  return true
}

User Permission

checkNotificationEnable

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 to the System Settings for that particular application where they can enable notifications.

383383
iZooto.checkNotificationEnable()

setSubscription

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 in to receive notifications.

iZooto.isSubscribe(isSubscribe:false)

Custom Badge Count

setBadgeCount

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

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:

iZooto.didReceiveNotificationExtensionRequest(bundleName :"YOUR_BUNDLE_NAME", soundName: "<SoundNameHere>",request: receivedRequest, bestAttemptContent: bestAttemptContent,contentHandler: contentHandler)
[iZooto didReceiveNotificationExtensionRequestWithBundleName:@"YOUR_BUNDLE_IDENTIFIER_NAME" soundName:@"Sound_Name_Here" request:self.receivedRequest bestAttemptContent:self.bestAttemptContent contentHandler: self.contentHandler];

🚧

Points to Note

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

Notification Handler

onNotificationReceived

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

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)
  }
}