PushProvider
PushProvider Class reference for Kustomer Chat iOS Core API .
Used to register and deregister devices with our push notification service. To enable push, see Push Keys and Certificates.
public class PushProvider : NSObject, UNUserNotificationCenterDelegate
shared
public static let shared: PushProvider
The central object for managing Kustomer push notification-related activities.
deviceToken
public var deviceToken: Data? { get }
The current device token. May or may not be registered for push notifications.
You need to have put PushManager.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
inside your application’s application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
method for this to work.
deviceTokenString
public var deviceTokenString: String? { get }
The deviceToken
as a UTF8 string
deregisterCurrentDeviceForPushNotifications(_:)
public func deregisterCurrentDeviceForPushNotifications(_ completion: @escaping ((Result<Void, KError>) -> Void))
If the current device has registered for Kustomer push notifications, deregisters it.
Requires an active internet connection.
Push notifications
didFailToRegisterForRemoteNotifications(error:)
public func didFailToRegisterForRemoteNotifications(error: Error)
If you’re using our push notifications, place this in your AppDelegate’s application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) method
didRegisterForRemoteNotifications(deviceToken:)
public func didRegisterForRemoteNotifications(deviceToken: Data)
If you’re using our push notifications, place this in your AppDelegate’s func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data)
deviceToken
: Pass the deviceToken
object that is passed to your AppDelegate
notificationIsFromKustomer
public func notificationIsFromKustomer(_ notification:UNNotification) -> Bool
Tells you if a push notification is from Kustomer. The threadIdentifier
of all UNNotifications from our platform is either "kustomer.app.chat" (remote pushes) or "kustomer.app.chat.local" (local push notifications)
requestAuthorizationForPush()
public func requestAuthorizationForPush()
Asks for permissions to send notifications.
You need to call this before push notifications will work. You can call it as many times as you want. If you’re already using UNUserNotificationCenter.current().center.requestAuthorization(...) somewhere else, you don’t need to call this method.
Source code of this method for advanced push users:
public func requestAuthorizationForPush(){
UNUserNotificationCenter.current().requestAuthorization(options:[.alert,.sound]) { (granted, error) in
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
registerDeviceForPushNotifications()
public func registerDeviceForPushNotifications()
UNUserNotificationCenterDelegate
userNotificationCenter(_:didReceive:withCompletionHandler:)
public func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
This gets called when you tap a push notification.
If you have set a unUserNotificationCenterDelegate
, your unUserNotificationCenterDelegate
will get called if the notification isn’t from Kustomer.
userNotificationCenter(_:willPresent:withCompletionHandler:)
public func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void)
This gets called when you get a push notification while the app is open. if you have set a unUserNotificationCenterDelegate
, your unUserNotificationCenterDelegate
will get called if the notification isn’t from Kustomer.
userNotificationCenter(_:openSettingsFor:)
public func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification: UNNotification?)
Updated over 3 years ago