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 applicationDeclaration
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 tokenNote
This method can be used Either if an application registered to APNS on it’s own or because it called the registerDevice() APIThrows
PushNotificationError in case the device token isn’t valid
Declaration
Swift
public func setDeviceToken(token: Data) throws
Parameters
token
Device Token Data
-
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:)Throws
PushNotificationError if launch options were not recognized
Declaration
Swift
public func setNotifyLaunchOptions(launchOptions: [UIApplicationLaunchOptionsKey: Any]?) throws
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:)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
-
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
-
Send an automatic push to the application to be delivered later
Declaration
Swift
public func scheduleAutoPush(afterSeconds seconds: TimeInterval, alertBody body: String?, applicationIconBadgeNumber badge: Int, customFields: [String: Any])
Parameters
seconds
the delay in seconds
body
the body of the alert
badge
the badge counter
customFields
some customFields to be attached