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
notificationFormatA 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.alertfield.Declaration
Swift
@discardableResult public func alert(_ alert: String?) -> MPNBuilderParameters
alertA string to be used for the
aps.alertfield value, or nil to clear it. -
Value of the
aps.alertfield.Declaration
Swift
public var alert: String? { get } -
Sets the
aps.alertfield with an int value.Declaration
Swift
@discardableResult public func badge(with badge: Int) -> MPNBuilderParameters
badgeAn int to be used for the
aps.badgefield value. -
Value of the
aps.badgefield as an int value.Declaration
Swift
public var badgeAsInt: Int? { get } -
Sets the
aps.badgefield with a string value.Declaration
Swift
@discardableResult public func badge(with badge: String?) -> MPNBuilderParameters
badgeA string to be used for the
aps.badgefield value, or nil to clear it. -
Value of the
aps.badgefield as a string value.Declaration
Swift
public var badgeAsString: String? { get } -
Sets the
aps.alert.bodyfield.Declaration
Swift
@discardableResult public func body(_ body: String?) -> MPNBuilderParameters
bodyA string to be used for the
aps.alert.bodyfield value, or nil to clear it. -
Value of the
aps.alert.bodyfield.Declaration
Swift
public var body: String? { get } -
Sets the
aps.alert.loc-argsfield.Declaration
Swift
@discardableResult public func bodyLocArguments(_ bodyLocArguments: [String]?) -> MPNBuilderParameters
bodyLocArgumentsAn array of strings to be used for the
aps.alert.loc-argsfield value, or nil to clear it. -
Value of the
aps.alert.loc-argsfield as an array of strings.Declaration
Swift
public var bodyLocArguments: [String]? { get } -
Sets the
aps.alert.loc-keyfield.Declaration
Swift
@discardableResult public func bodyLocKey(_ bodyLocKey: String?) -> MPNBuilderParameters
bodyLocKeyA string to be used for the
aps.alert.loc-keyfield value, or nil to clear it. -
Value of the
aps.alert.loc-keyfield.Declaration
Swift
public var bodyLocKey: String? { get } -
Sets the
aps.categoryfield.Declaration
Swift
@discardableResult public func category(_ category: String?) -> MPNBuilderParameters
categoryA string to be used for the
aps.categoryfield value, or nil to clear it. -
Value of the
aps.categoryfield.Declaration
Swift
public var category: String? { get } -
Sets the
aps.content-availablefield with an int value.Declaration
Swift
@discardableResult public func contentAvailable(with contentAvailable: Int) -> MPNBuilderParameters
contentAvailableAn int to be used for the
aps.content-availablefield value. -
Value of the
aps.content-availablefield as an int value.Declaration
Swift
public var contentAvailableAsInt: Int? { get } -
Sets the
aps.content-availablefield with a string value.Declaration
Swift
@discardableResult public func contentAvailable(with contentAvailable: String?) -> MPNBuilderParameters
contentAvailableA string to be used for the
aps.content-availablefield value, or nil to clear it. -
Value of the
aps.content-availablefield as a string value.Declaration
Swift
public var contentAvailableAsString: String? { get } -
Sets the
aps.mutable-contentfield with an int value.Declaration
Swift
@discardableResult public func mutableContent(with mutableContent: Int) -> MPNBuilderParameters
mutableContentAn int to be used for the
aps.mutable-contentfield value. -
Value of the
aps.mutable-contentfield as an int value.Declaration
Swift
public var mutableContentAsInt: Int? { get } -
Sets the
aps.mutable-contentfield with a string value.Declaration
Swift
@discardableResult public func mutableContent(with mutableContent: String?) -> MPNBuilderParameters
mutableContentA string to be used for the
aps.mutable-contentfield value, or nil to clear it. -
Value of the
aps.mutable-contentfield 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]?) -> MPNBuilderParameters
customDataA 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-imagefield.Declaration
Swift
@discardableResult public func launchImage(_ launchImage: String?) -> MPNBuilderParameters
launchImageA string to be used for the
aps.alert.launch-imagefield value, or nil to clear it. -
Value of the
aps.alert.launch-imagefield.Declaration
Swift
public var launchImage: String? { get } -
Sets the
aps.alert.action-loc-keyfield.Declaration
Swift
@discardableResult public func locActionKey(_ locActionKey: String?) -> MPNBuilderParameters
locActionKeyA string to be used for the
aps.alert.action-loc-keyfield value, or nil to clear it. -
Value of the
aps.alert.action-loc-keyfield.Declaration
Swift
public var locActionKey: String? { get } -
Sets the
aps.soundfield.Declaration
Swift
@discardableResult public func sound(_ sound: String?) -> MPNBuilderParameters
soundA string to be used for the
aps.soundfield value, or nil to clear it. -
Value of the
aps.soundfield.Declaration
Swift
public var sound: String? { get } -
Sets the
aps.thread-idfield.Declaration
Swift
@discardableResult public func threadId(_ threadId: String?) -> MPNBuilderParameters
threadIdA string to be used for the
aps.thread-idfield value, or nil to clear it. -
Value of the
aps.thread-idfield.Declaration
Swift
public var threadId: String? { get } -
Sets the
aps.alert.titlefield.Declaration
Swift
@discardableResult public func title(_ title: String?) -> MPNBuilderParameters
titleA string to be used for the
aps.alert.titlefield value, or nil to clear it. -
Value of the
aps.alert.titlefield.Declaration
Swift
public var title: String? { get } -
Sets the
aps.alert.subtitlefield.Declaration
Swift
@discardableResult public func subtitle(_ subtitle: String?) -> MPNBuilderParameters
subtitleA string to be used for the
aps.alert.subtitlefield value, or nil to clear it. -
Value of the
aps.alert.subtitlefield.Declaration
Swift
public var subtitle: String? { get } -
Sets the
aps.alert.title-loc-argsfield.Declaration
Swift
@discardableResult public func titleLocArguments(_ titleLocArguments: [String]?) -> MPNBuilderParameters
titleLocArgumentsAn array of strings to be used for the
aps.alert.title-loc-argsfield value, or nil to clear it. -
Value of the
aps.alert.title-loc-argsfield.Declaration
Swift
public var titleLocArguments: [String]? { get } -
Sets the
aps.alert.title-loc-keyfield.Declaration
Swift
@discardableResult public func titleLocKey(_ titleLocKey: String?) -> MPNBuilderParameters
titleLocKeyA string to be used for the
aps.alert.title-loc-keyfield value, or nil to clear it. -
Value of the
aps.alert.title-loc-keyfield.Declaration
Swift
public var titleLocKey: String? { get }
MPNBuilder Class Reference