SAPcpmsRemoteNotificationClient

public class SAPcpmsRemoteNotificationClient

This class is an API to upload an APNS device token that was retrieved using Apple’s AppDelegate method application:didRegisterForRemoteNotificationsWithDeviceToken delegate to SAPcpms
Usage sample:

// create URLs
let url = URL(string: <#your token registration url#>)!
let feedbackUrl = URL(string: <#your feedback url#>)!

// create SAPURLSession
let urlSession = SAPURLSession()

// create SAPcpmsRemoteNotificationClient with custom URL
let remoteNotificationClient = SAPcpmsRemoteNotificationClient(sapURLSession: urlSession, destinationURL: url, feedbackURL: feedbackUrl)

// when you received your APNS token in didRegisterForRemoteNotificationsWithDeviceToken delegate, you can upload it to SAPcpms using the registerDeviceToken method
remoteNotificationClient.registerDeviceToken(deviceToken) { error in
// error handling ...
}
  • Default initializer for using full URL as an input

    Declaration

    Swift

    public init(sapURLSession: SAPURLSession, destinationURL: URL, feedbackURL: URL? = nil)

    Parameters

    urlSession

    a SAPURLSession implementation that can be used to communicate with the SAPcpms

    destinationURL

    the full URL for push token registration

    feedbackURL

    (optional): the full URL for sending notification status

  • Convenience initializer for using SAPcpmsSettingsParameters as an input

    Declaration

    Swift

    public convenience init(sapURLSession: SAPURLSession, settingsParameters: SAPcpmsSettingsParameters)

    Parameters

    urlSession

    a SAPURLSession implementation that can be used to communicate with the SAPcpms

    settingsParameters

    an instance of the SAPcpmsSettingsParameters with prefilled values to be able to concatenate the SAPcpms URL; Required parameters: host, applicationID, deviceID

  • Upload the device token to the server

    Declaration

    Swift

    public func registerDeviceToken(_ deviceToken: Data, withParameters parameters: SAPcpmsRemoteNotificationParameters? = nil, completionHandler: @escaping (Error?) -> Void)

    Parameters

    deviceToken

    the device token from application:didRegisterForRemoteNotificationsWithDeviceToken delegate

    completionHandler

    called after the request completes; The parameter is an Error that could be nil.

  • Unregister the existing device token from the server

    Declaration

    Swift

    public func unregisterDeviceToken(completionHandler: @escaping (_ error: Error?) -> Void = SAPcpmsRemoteNotificationClient.defaultCompletionHandler)

    Parameters

    completionHandler

    called after the request completes; The parameter is an Error that could be nil.

  • Unregister the existing device token from the server

    Declaration

    Swift

    @available(*, deprecated, renamed: "unregisterDeviceToken")
    public func deregisterDeviceToken(completionHandler: @escaping (_ error: Error?) -> Void = SAPcpmsRemoteNotificationClient.defaultCompletionHandler)

    Parameters

    completionHandler

    called after the request completes; The parameter is an Error that could be nil.

  • Provide information about the notification status. This adjusts the notification status to ‘consumed’ on SAP Mobile Services Cockpit Reporting menu.

    Declaration

    Swift

    public func updateNotificationStatus(userInfo: [AnyHashable : Any], completionHandler: @escaping (_ error: Error?) -> Void = SAPcpmsRemoteNotificationClient.defaultCompletionHandler)

    Parameters

    userInfo

    userInfo parameter from the ‘didReceiveRemoteNotification’ application delegate

    completionHandler

    called after the request completes; The parameter is an Error that could be nil.

  • The default completion handler for SAPcpmsRemoteNotificationClient. Logs the error with the root logger if there is any.

    Declaration

    Swift

    public static func defaultCompletionHandler(_ error: Error?)

    Parameters

    error

    error that will be logged

  • Get list of all active topic subscriptions

    Throws

    error in case of failure

    Declaration

    Swift

    public func getAllSubscribedTopics() async throws -> [String]

    Return Value

    an array of subscribed topics if available

  • Subscribe to the topic that is passed as parameter

    Throws

    error in case of failure

    Declaration

    Swift

    public func subscribe(to topic: String) async throws

    Parameters

    topic

    a string value to subscribe

  • Unsubscribe from the topic that is passed as parameter

    Throws

    error in case of failure

    Declaration

    Swift

    public func unsubscribe(from topic: String) async throws

    Parameters

    topic

    a string value to unsubscribe from