NWPushManager

public class NWPushManager

The Object who manages all the interactions with Push Notifications, from APNS to PushNotification messages

  • A Flag stating if the SDK is actually registered with Newton Push Notification Module

    Declaration

    Swift

    public var isRegistered: Bool
  • Set the global push notification callback to be informed as soon as a push notification arrives

    Example of usage:

       do {
           try Newton.getSharedInstance()
               .getPushManager()
               .setPushCallback { [weak self] push in
               self?.textLog.log("A Push Notification has been handled. \(push.description)")
           }
       } catch {
           self.textLog.log("Error in Push Module \(error)")
       }
    

    Declaration

    Swift

    public func setPushCallback(callback: @escaping PushReceiveCallback) -> NWPushManager

    Parameters

    callback

    PushReceiveCallback to handle the notification

    Return Value

    the PushManager itself for chaining purposes

  • Register to Push Notification. Register to APNS instantly.

    Note

    An application could prefer to register to APNS on it’s own and hence pass the Device Token directly with setDeviceToken(token: Data)

    Attention

    This call at first time determines the pop-up asking if user allows push notification for the application

    Declaration

    Swift

    public func registerDevice()
  • Hook to Syscall to inform Newton that push notification were not accepted

    Attention

    Should be used inside the UIApplication application(_:didFailToRegisterForRemoteNotificationsWithError:)

    Declaration

    Swift

    public func didFailToRegisterForRemoteNotificationsWithError(error: Error)

    Parameters

    error

    the error returned from didFailToRegisterForRemoteNotificationsWithError

  • Inform Newton of the Device Token APNS gave

    Attention

    It’s preferrable to use this method in application(_:didRegisterForRemoteNotificationsWithDeviceToken:) passing the device token

    Note

    This method can be used Either if an application registered to APNS on it’s own or because it called the registerDevice() API

    Throws

    PushNotificationError in case the device token isn’t valid

    Declaration

    Swift

    public func setDeviceToken(token: Data) throws

    Parameters

    token

    Device Token Data

  • Inform Newton if registration failed

    Attention

    Use the Error object returned from the application(_:didFailToRegisterForRemoteNotificationsWithError:)

    Declaration

    Swift

    public func setRegistrationError(error: Error)

    Parameters

    error

    the Error received

  • Pass launch options to Newton at startup. If launch options contain a Push notification then the global notification PushReceiveCallback will be invoked In case its’ a remote notification received when the app was in background then an Analityc event of PushReceived (action: opened) is fired

    Attention

    It’s best to put a call to manager setNotifyLaunchOptions inside the system application(_:didFinishLaunchingWithOptions:)

    Declaration

    Swift

    public func setNotifyLaunchOptions(launchOptions options: [UIApplicationLaunchOptionsKey: Any]?)

    Parameters

    launchOptions

    the launch options dictionary

  • Hook to inform Newton that a remote notification has arrived If it’s a valid push notification then the global PushReceiveCallback will be invoked

    Attention

    Place this call inside application(_:didReceiveRemoteNotification:)

    -throws: Serialization on disk can be thrown

    Declaration

    Swift

    public func processRemoteNotification(userInfo: [AnyHashable: Any])

    Parameters

    userInfo

    userInfo dictionary

  • Hook to inform newton that a local notification has arrived

    Attention

    Place this call inside application(_:didReceive notification: UILocalNotification)

    Declaration

    Swift

    public func processLocalNotification(notification: UILocalNotification)

    Parameters

    notification

    the Local notification object

  • Show Interstitial Content if present. If a URL type push notification has been received this API can be used to present the URL inside a WebKit WebView.

    Note

    if an application wants to handle URL Push by itself then is preferrable to use a Standard Push with a URL placed inside custom fields

    Declaration

    Swift

    public func showInterstitialContent(onViewController controller: UIViewController, navigationDelegate delegate: WKNavigationDelegate?)

    Parameters

    controller

    the controller where the WKWebView is added to

    delegate

    the delegate that can be passed to have control of the navigation

  • Obtains the NWPushBuilder Object

    Declaration

    Swift

    public func getPushBuilder() -> NWPushBuilder

    Return Value

    NWPushBuilder