Documentation: Push Notifications Onsite Messaging REST API
  1. Documentation
  2. iOS App Push Notification
  3. iOS SDK Reference

iOS SDK Reference

PushAlert iOS Native SDK Reference

Just starting with iOS SDK?

Check out our iOS Setup SDK Guide

Parameter Data Type Description
Debugging
enableDebug Method Enable/Disable logging to help debug PushAlert implementation.
Initialization
initialize Method Initialises PushAlert. It should be called from the onCreate method of your Application class.
setInAppNotificationBehaviour Method To set in app behaviour, when your app is in focus.
onNotificationOpened Handler Use this delegate to perform custom logic, avoid manually relaunching or duplicating app navigation.
onForegroundNotificationReceived Handler To set your own notification receiver delegate. You can process additional data according to your app’s needs and optionally suppress the notification display.
onSubscribeListener Handler To set your listener when a user subscribes, this will help you to associate subscription id with your database.
Pre-defined Subscriber Properties
associateID Method To associate a subscriber with a particular unique id (your logic), can be used to send notification to a particular subscriber.
setEmail Method To set the email of the push subscriber.
setFirstName Method To set the first name of the push subscriber.
setLastName Method To set the last name of the push subscriber.
setGender Method To set the gender of the push subscriber.
setAge Method To set the age of the push subscriber.
setPhoneNum Method To set the phone number of the push subscriber.
Segments, Attributes and Trigger Events
addUserToSegment Method To add a subscriber to a segment.
removeUserFromSegment Method To remove a subscriber from a segment.
addAttributes Method To add custom attributes to a subscriber.
triggerEvent Method To send notification on custom events. Events are user interactions within your app.
e-Commerce
processAbandonedCart Method Add, update or remove abandoned cart notification.
addOutOfStockAlert Method To add an out of stock alert for a product.
isOutOfStockEnabled Method Check whether an out of stock alert is enabled for a product.
removeOutOfStockAlert Method To remove the out of stock alert of a product.
addPriceDropAlert Method To add a price drop alert for a product.
isPriceDropEnabled Method Check whether the price drop alert is enabled for a product.
removePriceDropAlert Method To remove the price drop alert of a product.
Subscriber Status
getSubscriberID Method Get the subscriber id, can be used to associate with the user details in your own database.
isUserSubscribed Method Check whether the user is subscribed.
isNotificationDisabled Method To check whether subscribers turned off notifications (not at system level).
disableNotification Method To disable/enable notifications for a subscriber (not at system level).
Conversion Reporting
reportConversion Method Report conversions without a value like register or sign-up.
reportConversionWithValue Method Report conversions with value (like purchase).
Opt-in
requestForPushNotificationPermission Method To initiate push notification permission manually.

Debugging

enableDebug

Enable logging to help debug any issue while setting up PushAlert on iOS. This method is static, so you can call it before PushAlert init.

Parameters Type Description
enable boolean Set true to enable.
//This will enable the debug mode.
PushAlert.enableDebug(enable: true);
Copy

Initialization

initialize

Initialises PushAlert to register the device for push notifications.

Parameters Type Description
app_id String Your PushAlert App ID, available at Dashboard->Settings->App
application UIApplication Your application instnace
settings [String : Any] An array containing settings in key value pairs. "auto_prompt" - (true or false), "provisional_auth" - (true or false), "in_app_behaviour" - (PAInAppBehaviour.NONE or PAInAppBehaviour.NOTIFICATION), "delay" - (Integer seconds)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    let paSettings:[String : Any] = ["auto_prompt": false, "provisional_auth": false, "delay": 5, "in_app_behaviour": PAInAppBehaviour.NOTIFICATION]
    PushAlert.enableDebug(enable: true)
    PushAlert.initialize(app_id: "YOUR_APP_ID", application: application, settings: paSettings)
}
Copy

setInAppNotificationBehaviour

To set in app behaviour, whether to show notification when your app is in focus.

Parameters Type Description
inAppBehaviour PAInAppBehaviour
  • NONE: Don't show notification when your app is in focus.
  • NOTIFICATION: Show notification when your app is in focus. Default
//Setting in-app behaviour (when app in focus) of notifications
PushAlert.setInAppNotificationBehaviour(inAppBehaviour: PAInAppBehaviour.NOTIFICATION)
Copy

onNotificationOpened

Sets a notification opener delegate to handle notification tap events. It will be called when a notification is tapped. Use this handler to perform any custom logic (notification id, extra data, url, category id and action id are available). Important: Do not manually relaunch or duplicate app navigation flows.

Parameters Type Description
onNotificationOpened PushAlertNotificationOpenerDelegate
    Set a delegate to get access to the notificaiton data when it is tapped.
//Setting onNotificationOpened, trigger when a notification is tapped
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate, PushAlertSubscribeDelegate, PushAlertNotificationOpenerDelegate, PushAlertForegroundNotificationReceiverDelegate{
    
    ...
    
    func notificationOpened(paNotificationOpened: PANotificationOpened) {
        print("Notification CLicked", paNotificationOpened.getNotificationId())
    }
    
    ...
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        ...
        
        PushAlert.onNotificationOpened = self
        
        ...
    }
    
    ...
}
Copy

onForegroundNotificationReceived

Set a custom notification receiver delegate to handle incoming notifications. You can access and use extra data as needed, or prevent the notification from being displayed.

Parameters Type Description
onForegroundNotificationReceived PushAlertForegroundNotificationReceiverDelegate
    Set a delegate to access payload when notification is received (app in-focus).
//Setting notification received in-app behaviour (when app in focus) of notifications
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate, PushAlertSubscribeDelegate, PushAlertNotificationOpenerDelegate, PushAlertForegroundNotificationReceiverDelegate{
    
    ...
    
    func foregroundNotificationReceived(notification: PANotification) -> Bool {
        print("Title: ", notification.getTitle())
        let extra = notification.getExtraData()
        return false; //Set true to prevent notification to show
    }
    
    ...
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        ...
        
        PushAlert.onForegroundNotificationReceived = self
        
        ...
    }
    
    ...
}
Copy

onSubscribeListener

Set your listener to when a user subscribes, this will help you to associate the subscriber id with user details in your database. You can further use this subscriber id to send notifications to a particular user as well as other operations using REST API.

Parameters Type Description
onSubscribeListener PushAlertSubscribeDelegate
    Set a delegate to receive subscription events from PushAlert.
//Setting onSubscribeListener to get subscriber id on subscribe.
class AppDelegate: NSObject, UIApplicationDelegate, UNUserNotificationCenterDelegate, PushAlertSubscribeDelegate, PushAlertNotificationOpenerDelegate, PushAlertForegroundNotificationReceiverDelegate{
    
    ...
    
    func onSubscribe(subs_id: String) {
        print("Subscribed ID: ", subs_id)
    }
    
    ...
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        ...
        
        PushAlert.onSubscribeListener = self
        
        ...
    }
    
    ...
}
Copy

Pre-defined Subscriber Properties

associateID

To associate a subscriber with a unique id (your logic). Can be used to send notifications to a particular subscriber or other operations using REST API.

Parameters Type Description
id String Unique ID for a subscriber
//Setting unique ID to a subscriber
PushAlert.associateID(id: "UNIQUE_ID");
Copy

setEmail

To set the email address of the push subscriber.

Parameters Type Description
email String Email id of the subscriber
//Setting email for a subscriber
PushAlert.setEmail(email: "someone@korner.space");
Copy

setFirstName

To set the first name of the push subscriber.

Parameters Type Description
firstName String First name of the subscriber
//Setting first name of the subscriber
PushAlert.setFirstName(firstName: "Alex");
Copy

setLastName

To set the last name of the push subscriber.

Parameters Type Description
lastName String Last name of the subscriber
//Setting last name of the subscriber
PushAlert.setLastName(lastName: "Jones");
Copy

setGender

To set the gender of the push subscriber.

Parameters Type Description
gender String Gender of the subscriber
//Setting gender of the subscriber
PushAlert.setGender(gender: "male");
Copy

setAge

To set the age of the push subscriber.

Parameters Type Description
age int Age of the subscriber
//Setting age of the subscriber
PushAlert.setAge(age: 29);
Copy

setPhoneNum

To set the phone number of the push subscriber.

Parameters Type Description
phoneNum String Phone number of the subscriber
//Setting phone number of the subscriber
PushAlert.setPhoneNum(phoneNum: "(000) 000-0000");
Copy

Segments, Attributes and Trigger Events

addUserToSegment

Add a push subscriber to a segment.

Parameters Type Description
seg_id int Segment ID
//Add a subscriber to a segment
PushAlert.addUserToSegment(seg_id: 12404);
Copy

removeUserFromSegment

Remove a push subscriber from a segment.

Parameters Type Description
seg_id int Segment ID
//Remove a subscriber from a segment
PushAlert.removeUserFromSegment(seg_id: 12404);
Copy

addAttributes

Add custom attributes to a push subscriber.

Parameters Type Description
attributes Map <String, String> Attribute name, value map
//Adding attributes to a subscriber
var attr: [String: String] = [:]
attr["language"] = "es";
attr["zip_code"] = "98125";
PushAlert.addAttributes(attributes: attrs)
Copy

triggerEvent

Events are user interactions with content on your app. Examples of custom events can be a download, link click, scroll to a particular part of the page, playing a video etc. With triggerEvent you can initiate push notifications for a particular event.

Parameters Type Description
eventCategory String The object or page that was interacted with (e.g. 'Video')
eventAction String The type of interaction (e.g. 'play','pause','stopped').
eventLabel String Optional. Used for categorizing events. (e.g. 'Launch Campaign').
eventValue int Optional. A numeric value associated with the event (e.g. 2017).
//Trigger events
PushAlert.triggerEvent(eventCategory: "videos", eventAction: "play", eventLabel: "video_id", eventValue: 132);
PushAlert.triggerEvent(eventCategory: "pdf", eventAction: "download", eventLabel: "Top Marketing Strategies");
Copy

E-Commerce

processAbandonedCart

Update or delete abandoned cart information which are used to send abandoned cart notifications.

Parameters Type Description
action AbandonedCartAction
  • UPDATE: Updates the abandoned cart data.
  • DELETE: Removes abandoned cart information.
data Map <String, String> Cart information in key, value map
//Updating cart information for abandoned cart notifications, this can be called whenever there are changes in cart
var data: [String: String] = [:]
data["customer_name"] = "Alex"
data["image"] = "https://cdn.pushalert.co/large-image/image9-16_test.png"
data["total_items"] = "3"
data["total_amount"] = "12.99"
data["cart_url"] = "https://korner.space/blog/cart/"
data["checkout_url"] = "https://korner.space/blog/checkout/"
PushAlert.processAbandonedCart(action: AbandonedCartAction.UPDATE, data: data)


//Deleting cart information to remove abandoned cart notifications from the queue, you can call this on order completion or when cart is emptied.
PushAlert.processAbandonedCart(action: AbandonedCartAction.DELETE, data: nil)
Copy

addOutOfStockAlert

Subscribe the user to a back in stock alert for a specific product. When the product comes back in stock a notification will be sent.

Parameters Type Description
product_id int Product ID
variant_id int Variant id of the given product.
price double Price of the product for the given variant.
extras Map <String, String> Extra information in key, value map
//Adding in-stock alert for a subscriber
var extras: [String: String] = [:]
extras["name"] = "Alex"
PushAlert.addOutOfStockAlert(product_id: 2432, variant_id: 1, price: 19.99, extras: extras)
Copy

isOutOfStockEnabled

Check whether the out of stock alert is enabled for a given variant of the product.

Parameters Type Description
product_id int Product ID
variant_id int Variant id of the given product.
//Checking out of stock alert is enabled for a given variant of the product.
var isEnabled: Bool = PushAlert.isOutOfStockEnabled(product_id: Int2432, variant_id: 1)
Copy

removeOutOfStockAlert

To remove out of stock alerts for a given variant of the product for a push subscriber.

Parameters Type Description
product_id int Product ID
variant_id int Variant id of the given product.
//Removing out of stock alert for a given variant of the product.
PushAlert.removedOutOfStockAlert(product_id: 2432, variant_id: 1)
Copy

addPriceDropAlert

Add a price drop alert for a particular product for a subscriber. When the product price goes down a notification will be sent.

Parameters Type Description
product_id int Product ID
variant_id int Variant id of the given product.
price double Price of the product for the given variant.
extras Map <String, String> Extra information in key, value map
//Adding price drop alert for a subscriber
var extras: [String: String] = [:]
extras["name"] = "Alex"

PushAlert.addPriceDropAlert(product_id: 2432, variant_id: 1, price: 19.99, extras: extras)
Copy

isPriceDropEnabled

Check whether a price drop alert is enabled for a given variant of the product.

Parameters Type Description
product_id int Product ID
variant_id int Variant id of the given product.
//Checking price drop alert is enabled for a given variant of the product.
var isEnabled: Bool = PushAlert.isPriceDropEnabled(product_id: 2432, variant_id: 1)
Copy

removePriceDropAlert

To remove price drop alerts for a given variant of the product for a push subscriber.

Parameters Type Description
product_id int Product ID
variant_id int Variant id of the given product.
//Removing price drop alert for a given variant of the product.
PushAlert.removePriceDropAlert(product_id: 2432, variant_id: 1)
Copy

Subscriber Status

getSubscriberID

Get subscriber id of the user (nil if not subscribed). Returns a String.

//Getting PushAlert subscriber ID.
let subID: String = PushAlert.getSubscriberID()!
Copy

isUserSubscribed

Check whether the user subscribed. Returns a boolean.

//Checking push subscription status.
let isUserSubscribed: Bool = PushAlert.isUserSubscribed()
Copy

isNotificationDisabled

Check whether notifications are disabled by a subscriber (not at system level, by using method disableNotification). Returns a boolean.

//Checking notification status.
let isNotificationDisabled: Bool = PushAlert.isNotificationDisabled()
Copy

disableNotification

To disable/enable notifications for a push subscriber. This does not unsubscribe the user. You can use this method to give an option to the user in your app preferences.

Parameters Type Description
disable boolean Set true to disable notification for the subscriber.
//Disable notification for the subscriber.
PushAlert.disableNotification(disable: true)
Copy

Conversion Reporting

reportConversion

Report a conversion without a value like register, video played, sign-up etc. This will associate the notification with conversion, and help you to analyze your goal.

Parameters Type Description
conversion_name String Conversion name like register, download
//Reporting conversion without a value.
PushAlert.reportConversion(conversion_name: "register")
Copy

reportConversionWithValue

Report a conversion with a value for e.g., purchase with a numeric value 9.99. This will associate the notification with conversion, and help you to analyze them.

Parameters Type Description
conversion_name String Conversion name like purchase
conversion_value double Conversion value like 9.99
//Reporting conversion with a value.
PushAlert.reportConversionWithValue(conversion_name: "purchase", conversion_value: 9.99)
Copy

Opt-in

requestForPushNotificationPermission

To initiate the push notification permission process manually. Does nothing, if already subscribed.

//Initialising push subscription manually
PushAlert.requestForPushNotificationPermission()
Copy