PushNotifications
@objc
public final class PushNotifications : NSObject
The top-level entrypoint to the Beams Swift SDK.
-
The object that acts as the delegate of push notifications.
Declaration
Swift
public weak var delegate: InterestsChangedDelegate?
-
Creates a
PushNotifications
object with a giveninstanceId
.Declaration
Swift
@objc public init(instanceId: String)
Parameters
instanceId
The instance identifier (from your app dashboard).
-
Returns a shared singleton PushNotifications object that can be accessed from anywhere in your project.
Declaration
Swift
@objc public static let shared: PushNotificationsStatic.Type
-
Start PushNotifications service.
Declaration
Swift
@objc public func start()
-
Register to receive remote notifications via Apple Push Notification service.
Convenience method is using
.alert
,.sound
, and.badge
as default authorization options.Declaration
Swift
@objc public func registerForRemoteNotifications()
-
Register to receive remote notifications via Apple Push Notification service.
-
Register to receive remote notifications via Apple Push Notification service.
Declaration
Swift
@objc public func registerForRemoteNotifications(options: NSApplication.RemoteNotificationType)
Parameters
options
A bit mask specifying the types of notifications the app accepts. See NSApplication.RemoteNotificationType for valid bit-mask values.
-
Set user id.
Declaration
Swift
@objc public func setUserId(_ userId: String, tokenProvider: TokenProvider, completion: @escaping (Error?) -> Void)
Parameters
userId
User id.
tokenProvider
Token provider that will be used to generate the token for the user that you want to authenticate.
completion
The block to execute after attempt to set user id has been made.
-
Disable Beams service.
This will remove everything associated with the Beams from the device and Beams server.
Declaration
Swift
@objc public func stop(completion: @escaping () -> Void)
Parameters
completion
The block to execute after the device has been deleted from the server.
-
Clears all the state on the SDK leaving it in the empty started state.
This will remove the current user and all the interests associated with it from the device and Beams server. Device is now in a fresh state, ready for new subscriptions or user being set.
Declaration
Swift
@objc public func clearAllState(completion: @escaping () -> Void)
Parameters
completion
The block to execute after the device has been deleted from the server.
-
Register device token with PushNotifications service.
Precondition
deviceToken
should not be nil.Declaration
Swift
@objc public func registerDeviceToken(_ deviceToken: Data)
Parameters
deviceToken
A token that identifies the device to APNs.
-
Subscribes the device to an interest.
Precondition
interest
should not be nil.Throws
An error of type
InvalidInterestError
Declaration
Swift
@objc public func addDeviceInterest(interest: String) throws
Parameters
interest
Interest that you want to subscribe your device to.
-
Sets the subscriptions state for the device. Any interests not in the set will be unsubscribed from, so this will replace the interest set by the one provided.
Precondition
interests
should not be nil.Throws
An error of type
MultipleInvalidInterestsError
Declaration
Swift
@objc public func setDeviceInterests(interests: [String]) throws
Parameters
interests
Interests that you want to subscribe your device to.
-
Unsubscribe the device from an interest.
Precondition
interest
should not be nil.Throws
An error of type
InvalidInterestError
Declaration
Swift
@objc public func removeDeviceInterest(interest: String) throws
Parameters
interest
Interest that you want to unsubscribe your device from.
-
Unsubscribes the device from all the interests.
- Tag: clearDeviceInterests
Declaration
Swift
@objc public func clearDeviceInterests() throws
-
Get the interest subscriptions that the device is currently subscribed to.
Declaration
Swift
@objc public func getDeviceInterests() -> [String]?
Return Value
Array of interests
-
Handle Remote Notification.
Declaration
Swift
@discardableResult @objc public func handleNotification(userInfo: [AnyHashable : Any]) -> RemoteNotificationType
Parameters
userInfo
Remote Notification payload.