class Message implements Serializable

An APNS Message representation.

Note: All strings given to this class must be in UTF-8 to create a valid message

Methods

static MessageBuilder
builder()

Get a builder to constuct a message

__construct(string $deviceToken, Certificate $certificate, array|null $alert, int|null $badge, string|null $sound, array|json|null $payload, string $category, boolean $contentAvailable, DateTime $expiresAt = null)

Construct Message

boolean
isCompatibleWithSmallPayloadSize()

Check if this message is short enough to be send to iOS 7 or OS X Note: iOS 8 support messages up to 2048 bytes, OS X and iOS 7 and below support messages up to 256 bytes

string
getDeviceToken()

Get the device token of the receiving device

getCertificate()

Get the certificate that should be used for this message

int
getExpiresAt()

Get the moment this message expires

string|array
getAlert()

Get the current alert

int|null
getBadge()

Get the value of the badge as set in this message

string|null
getSound()

Get the sound that will be played when this message is received

string|null
getCategory()

Get the category identifier that will be used to determine custom actions

boolean
getContentAvailable()

Get newsstand content availability flag that will trigger the newsstand item to download new content

array|null
getPayload()

Get the current payload

string
getJson()

Get the JSON payload that should be send to the APNS

string
serialize()

String representation of object

unserialize(string $serialized)

Constructs the object from serialized data

string
__toString()

Get a string representation of this object

Details

at line 29
static MessageBuilder builder()

Get a builder to constuct a message

Return Value

MessageBuilder

at line 49
__construct(string $deviceToken, Certificate $certificate, array|null $alert, int|null $badge, string|null $sound, array|json|null $payload, string $category, boolean $contentAvailable, DateTime $expiresAt = null)

Construct Message

Parameters

string $deviceToken Receiver of this message
Certificate $certificate The certificate that must be used for the APNS connection this message is send over
array|null $alert The alert to display or null to set no alert
int|null $badge The badge number to display
string|null $sound String of the sound to play, null for no sound sound
array|json|null $payload The payload to send as array or JSON string
string $category Category identifier for the app to display the correct custom actions
boolean $contentAvailable True when new newsstand content is available, false when not
DateTime $expiresAt Date until the message should be stored for delivery

Exceptions

InvalidArgumentException On invalid or missing arguments
LengthException On too long message

at line 76
boolean isCompatibleWithSmallPayloadSize()

Check if this message is short enough to be send to iOS 7 or OS X Note: iOS 8 support messages up to 2048 bytes, OS X and iOS 7 and below support messages up to 256 bytes

Return Value

boolean Wheter you can send this message savely to older OSses

at line 86
string getDeviceToken()

Get the device token of the receiving device

Return Value

string

at line 96
Certificate getCertificate()

Get the certificate that should be used for this message

Return Value

Certificate

at line 106
int getExpiresAt()

Get the moment this message expires

Return Value

int Unix timestamp of expiry moment or zero if no specific expiry moment is set

at line 116
string|array getAlert()

Get the current alert

Return Value

string|array

at line 126
int|null getBadge()

Get the value of the badge as set in this message

Return Value

int|null

at line 136
string|null getSound()

Get the sound that will be played when this message is received

Return Value

string|null

at line 146
string|null getCategory()

Get the category identifier that will be used to determine custom actions

Return Value

string|null

at line 156
boolean getContentAvailable()

Get newsstand content availability flag that will trigger the newsstand item to download new content

Return Value

boolean True when new content is available, false when not

at line 166
array|null getPayload()

Get the current payload

Return Value

array|null

at line 177
string getJson()

Get the JSON payload that should be send to the APNS

Return Value

string

Exceptions

RuntimeException When unable to create JSON, for example because of non-UTF-8 characters

at line 232
string serialize()

String representation of object

Return Value

string

at line 249
unserialize(string $serialized)

Constructs the object from serialized data

Parameters

string $serialized Serialized data

at line 266
string __toString()

Get a string representation of this object

Return Value

string