MPNBuilder
public class MPNBuilder
Utility class that provides methods to build or parse the JSON structure used to represent the format of a push notification.
It provides properties and methods to get and set the fields of a push notification, following the format specified by Apple’s Push Notification service (APNs).
This format is compatible with MPNSubscription.notificationFormat
.
See also
MPNSubscription.notificationFormat
-
Creates an empty object to be used to create a push notification format from scratch.
Use setters methods to set the value of push notification fields.
Declaration
Swift
public init()
-
Creates an object based on the specified push notification format.
Use properties and setter methods to get and set the value of push notification fields.
Precondition
the notification must be a valid JSON structure.
Declaration
Swift
public init?(notificationFormat: String)
Parameters
notificationFormat
A JSON structure representing a push notification format.
-
Produces the JSON structure for the push notification format specified by this object.
Declaration
Swift
public func build() -> String
-
Sets the
aps.alert
field.Declaration
Swift
@discardableResult public func alert(_ alert: String?) -> MPNBuilder
Parameters
alert
A string to be used for the
aps.alert
field value, or nil to clear it. -
Value of the
aps.alert
field.Declaration
Swift
public var alert: String? { get }
-
Sets the
aps.alert
field with an int value.Declaration
Swift
@discardableResult public func badge(with badge: Int) -> MPNBuilder
Parameters
badge
An int to be used for the
aps.badge
field value. -
Value of the
aps.badge
field as an int value.Declaration
Swift
public var badgeAsInt: Int? { get }
-
Sets the
aps.badge
field with a string value.Declaration
Swift
@discardableResult public func badge(with badge: String?) -> MPNBuilder
Parameters
badge
A string to be used for the
aps.badge
field value, or nil to clear it. -
Value of the
aps.badge
field as a string value.Declaration
Swift
public var badgeAsString: String? { get }
-
Sets the
aps.alert.body
field.Declaration
Swift
@discardableResult public func body(_ body: String?) -> MPNBuilder
Parameters
body
A string to be used for the
aps.alert.body
field value, or nil to clear it. -
Value of the
aps.alert.body
field.Declaration
Swift
public var body: String? { get }
-
Sets the
aps.alert.loc-args
field.Declaration
Swift
@discardableResult public func bodyLocArguments(_ bodyLocArguments: [String]?) -> MPNBuilder
Parameters
bodyLocArguments
An array of strings to be used for the
aps.alert.loc-args
field value, or nil to clear it. -
Value of the
aps.alert.loc-args
field as an array of strings.Declaration
Swift
public var bodyLocArguments: [String]? { get }
-
Sets the
aps.alert.loc-key
field.Declaration
Swift
@discardableResult public func bodyLocKey(_ bodyLocKey: String?) -> MPNBuilder
Parameters
bodyLocKey
A string to be used for the
aps.alert.loc-key
field value, or nil to clear it. -
Value of the
aps.alert.loc-key
field.Declaration
Swift
public var bodyLocKey: String? { get }
-
Sets the
aps.category
field.Declaration
Swift
@discardableResult public func category(_ category: String?) -> MPNBuilder
Parameters
category
A string to be used for the
aps.category
field value, or nil to clear it. -
Value of the
aps.category
field.Declaration
Swift
public var category: String? { get }
-
Sets the
aps.content-available
field with an int value.Declaration
Swift
@discardableResult public func contentAvailable(with contentAvailable: Int) -> MPNBuilder
Parameters
contentAvailable
An int to be used for the
aps.content-available
field value. -
Value of the
aps.content-available
field as an int value.Declaration
Swift
public var contentAvailableAsInt: Int? { get }
-
Sets the
aps.content-available
field with a string value.Declaration
Swift
@discardableResult public func contentAvailable(with contentAvailable: String?) -> MPNBuilder
Parameters
contentAvailable
A string to be used for the
aps.content-available
field value, or nil to clear it. -
Value of the
aps.content-available
field as a string value.Declaration
Swift
public var contentAvailableAsString: String? { get }
-
Sets the
aps.mutable-content
field with an int value.Declaration
Swift
@discardableResult public func mutableContent(with mutableContent: Int) -> MPNBuilder
Parameters
mutableContent
An int to be used for the
aps.mutable-content
field value. -
Value of the
aps.mutable-content
field as an int value.Declaration
Swift
public var mutableContentAsInt: Int? { get }
-
Sets the
aps.mutable-content
field with a string value.Declaration
Swift
@discardableResult public func mutableContent(with mutableContent: String?) -> MPNBuilder
Parameters
mutableContent
A string to be used for the
aps.mutable-content
field value, or nil to clear it. -
Value of the
aps.mutable-content
field as a string value.Declaration
Swift
public var mutableContentAsString: String? { get }
-
Sets fields in the root of the notification format (excluding
aps
).Declaration
Swift
@discardableResult public func customData(_ customData: [String : Any]?) -> MPNBuilder
Parameters
customData
A dictionary to be used for fields in the root of the notification format (excluding
aps
), or nil to clear them. -
Fields in the root of the notification format (excluding
aps
).Declaration
Swift
public var customData: [String : Any]? { get }
-
Sets the
aps.alert.launch-image
field.Declaration
Swift
@discardableResult public func launchImage(_ launchImage: String?) -> MPNBuilder
Parameters
launchImage
A string to be used for the
aps.alert.launch-image
field value, or nil to clear it. -
Value of the
aps.alert.launch-image
field.Declaration
Swift
public var launchImage: String? { get }
-
Sets the
aps.alert.action-loc-key
field.Declaration
Swift
@discardableResult public func locActionKey(_ locActionKey: String?) -> MPNBuilder
Parameters
locActionKey
A string to be used for the
aps.alert.action-loc-key
field value, or nil to clear it. -
Value of the
aps.alert.action-loc-key
field.Declaration
Swift
public var locActionKey: String? { get }
-
Sets the
aps.sound
field.Declaration
Swift
@discardableResult public func sound(_ sound: String?) -> MPNBuilder
Parameters
sound
A string to be used for the
aps.sound
field value, or nil to clear it. -
Value of the
aps.sound
field.Declaration
Swift
public var sound: String? { get }
-
Sets the
aps.thread-id
field.Declaration
Swift
@discardableResult public func threadId(_ threadId: String?) -> MPNBuilder
Parameters
threadId
A string to be used for the
aps.thread-id
field value, or nil to clear it. -
Value of the
aps.thread-id
field.Declaration
Swift
public var threadId: String? { get }
-
Sets the
aps.alert.title
field.Declaration
Swift
@discardableResult public func title(_ title: String?) -> MPNBuilder
Parameters
title
A string to be used for the
aps.alert.title
field value, or nil to clear it. -
Value of the
aps.alert.title
field.Declaration
Swift
public var title: String? { get }
-
Sets the
aps.alert.subtitle
field.Declaration
Swift
@discardableResult public func subtitle(_ subtitle: String?) -> MPNBuilder
Parameters
subtitle
A string to be used for the
aps.alert.subtitle
field value, or nil to clear it. -
Value of the
aps.alert.subtitle
field.Declaration
Swift
public var subtitle: String? { get }
-
Sets the
aps.alert.title-loc-args
field.Declaration
Swift
@discardableResult public func titleLocArguments(_ titleLocArguments: [String]?) -> MPNBuilder
Parameters
titleLocArguments
An array of strings to be used for the
aps.alert.title-loc-args
field value, or nil to clear it. -
Value of the
aps.alert.title-loc-args
field.Declaration
Swift
public var titleLocArguments: [String]? { get }
-
Sets the
aps.alert.title-loc-key
field.Declaration
Swift
@discardableResult public func titleLocKey(_ titleLocKey: String?) -> MPNBuilder
Parameters
titleLocKey
A string to be used for the
aps.alert.title-loc-key
field value, or nil to clear it. -
Value of the
aps.alert.title-loc-key
field.Declaration
Swift
public var titleLocKey: String? { get }