Share via


apns object

 

Enables you to send push notifications to an iOS app from Microsoft Azure Mobile Services server scripts using Azure Notification Hubs. The payload for an APNS notification has the following JSON format:

{
    aps: {
        badge: badge_number,
        alert: 'alert_text',
        sound: 'sound_file',
        payload: payload_object,
        expiry: expire_date
    }
}

Methods

  • createNativeRegistration(token, tags, options, callback)
    Creates a native APNS registration.

    Parameters

    Name

    Type

    Argument

    Description

    token

    string

    The device token.

    tags

    string | array

    A single tag or array of tags (comma-separated list, no spaces).

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • createOrUpdateNativeRegistration(registrationId, token, tags, options, callback)
    Creates or updates a native APNS registration.

    Parameters

    Name

    Type

    Argument

    Description

    registrationId

    string

    The registration identifier.

    token

    string

    The device token.

    tags

    string | array

    A single tag or array of tags (comma-separated list, no spaces).

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • createOrUpdateTemplateRegistration(registrationId, token, template, options, callback)
    Creates or updates a template registration.

    Parameters

    Name

    Type

    Argument

    Description

    registrationId

    string

    The registration identifier.

    token

    string

    The device token.

    template

    string | array

    The JSON payload for the message as specified below.

    Name

    Type

    Argument

    Description

    badge

    number

    <optional>

    The number to display over the app icon.

    alert

    string

    <optional>

    The alert text.

    sound

    string

    <optional>

    The sound file name.

    payload

    object

    <optional>

    The payload object that contains the notification text.

    expiry

    date

    <optional>

    The expiration date.

    When the payload is a string, follow the APNS format.

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • createTemplateRegistration(token, tags, template, options, callback)
    Creates a template registration.

    Parameters

    Name

    Type

    Argument

    Description

    token

    string

    The device token.

    tags

    string | array

    A single tag or array of tags (comma-separated list, no spaces).

    template

    string | array

    The JSON payload for the message as specified below.

    Name

    Type

    Argument

    Description

    badge

    number

    <optional>

    The number to display over the app icon.

    alert

    string

    <optional>

    The alert text.

    sound

    string

    <optional>

    The sound file name.

    payload

    object

    <optional>

    The payload object that contains the notification text.

    expiry

    date

    <optional>

    The expiration date.

    When the payload is a string, follow the APNS format.

    options

    object

    <optional>

    The request options or callback function.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • listRegistrationsByToken(token, options, callback)
    Retrieves a registration by device token.

    Parameters

    Name

    Type

    Argument

    Description

    token

    string

    The device token.

    options

    object

    <optional>

    The request options or callback function. Additional properties are passed as headers.

    Name

    Type

    Argument

    Description

    top

    object

    <optional>

    Specifies the maximum number of registration to obtain from the call.

    skip

    object

    <optional>

    Specifies the number of registrations to skip in the call.

    callback

    object

    <optional>

    A JSON object that specifies the success and error callback functions.

  • send(tags, payload, callback)
    Sends an APNS notification.

    Parameters

    Name

    Type

    Description

    tags

    string

    A single tag or tag expression. When null, the message is sent to all template registrations.

    payload

    object | string

    The JSON payload for the message as specified below.

    Name

    Type

    Argument

    Description

    badge

    number

    <optional>

    The number to display over the app icon.

    alert

    string

    <optional>

    The alert text.

    sound

    string

    <optional>

    The sound file name.

    payload

    object

    <optional>

    The payload object that contains the notification text.

    expiry

    date

    <optional>

    The expiration date.

    When the payload is a string, follow the APNS format.

    callback

    object

    A JSON object that specifies the success and error callback functions.

  • updateTemplateRegistration(registrationId, token, template, options, callback)
    Updates an existing template registration.

    Parameters

    Name

    Type

    Argument

    Description

    registrationId

    string

    The registration identifier.

    token

    string

    The device token.

    template

    string | array

    The JSON payload for the message as specified below.

    Name

    Type

    Argument

    Description

    badge

    number

    <optional>

    The number to display over the app icon.

    alert

    string

    <optional>

    The alert text.

    sound

    string

    <optional>

    The sound file name.

    payload

    object

    <optional>

    The payload object that contains the notification text.

    expiry

    date

    <optional>

    The expiration date.

    When the payload is a string, follow the APNS format.

    options

    object

    <optional>

    The request options.

    callback

    object

    A JSON object that specifies the success and error callback functions.

Remarks

For an example of how to send push notifications from your mobile service to an iOS app, see Add push notifications to your Mobile Services app.

The apns object is obtained from the push object in a server script. For a complete example, see Get started with push notifications.

The payload for an APNS notification has the following JSON format:

{
    aps: {
        badge: badge_number,
        alert: 'alert_text',
        sound: 'sound_file',
        payload: payload_object,
        expiry: expire_date
    }
}

When the alert field of the payload object is specified, the assigned text value is displayed as a toast notification. This notification is displayed even when the app is not running. The data in the payload field of the payload object is only displayed when the app is running.

Example

The following example calls the send method to send a text notification to a specific device when a new item is inserted into a table.

function insert(item, user, request) {
    request.execute();
    push.apns.send(null, {
        alert: "Alert: " + item.text,
        payload: {
            inAppMessage: "Hey, a new item arrived: '" + item.text + "'"
        }
    });
}

See Also

Get started with push notifications
Mobile Services JavaScript (Node.js) backend library
apns object
gcm object
mpns object
wns object