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.
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. |
navigateToSettings | Method | Can be used to re-direct the users to the App Settings page to check the notification permissions, etc. |
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
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
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
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.
iZooto.checkNotificationEnable()
setSubscription
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.setSubscription(isSubscribe:Bool)
navigateToSettings
navigateToSettings
This method can be used to take the users to the App Settings page to check the notification permissions and/or other app settings. This method becomes useful if the user has disabled notifications and you would like to have an option inside the app itself to re-direct the user to the App Settings page to allow the user to re-enable the notification permissions. The method can be called at the click of a button or any other event as per requirement.
navigateToSettings()
Custom Badge Count
setBadgeCount
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
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
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
}
@available(iOS 13.0, *)
func sceneWillEnterForeground(_ scene: UIScene) {
UIApplication.shared.applicationIconBadgeNumber = 0
}
Pass
0
in thesetBadgeCount
method to default to an incremental value.
Sound
setNotificationSound
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
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
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)
}
}
Updated 4 months ago