mpns object
Enables you to send push notifications to a Windows Phone 8.0 or Windows Phone 8.1 Silverlight app from Microsoft Azure Mobile Services server scripts using Azure Notification Hubs.
Methods
createFlipTileRegistration(channel, tags, template, options, callback)
Creates a registration with a flip Tile template. (Only Windows Phone version 7.8 or later.)Parameters
Name
Type
Argument
Description
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
template
object
The registration template.
Name
Type
Description
backgroundImage
string
The URI of the background image for the tile.
count
string
The number that appears on the tile.
title
string
The title text of the tile.
backBackgroundImage
string
The URI of the image that is shown on the backside of the tile.
backTitle
string
The title text for the backside of the tile.
backContent
string
The text for the backside of the tile.
id
string
The ID of a related, secondary tile.
smallBackgroundImage
string
The URI for the background image for the tile when it is reduced to its small size.
wideBackgroundImage
string
The URI for the background image for the tile when it is expanded to its wide size.
wideBackContent
string
Content for the back tile when the tile is expanded to its wide size.
wideBackBackgroundImage
string
The URI for the image to be on the backside of the tile when the tile is expanded to its wide size.
options
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
createNativeRegistration(channel, tags, optionsOrCallback, callback)
Creates a native MPNS registration.Parameters
Name
Type
Argument
Description
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
optionsOrCallback
object
<optional>
The request options or callback.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
createOrUpdateNativeRegistration(registrationId, channel, tags, optionsOrCallback, callback)
Creates or updates a native MPNS registration.Parameters
Name
Type
Argument
Description
registrationId
string
The registration identifier.
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
optionsOrCallback
object
<optional>
The request options or callback.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
createOrUpdateRawTemplateRegistration(registrationId, channel, tags, template, optionsOrCallback, callback)
Creates or updates a custom template registration.Parameters
Name
Type
Argument
Description
registrationId
string
The registration identifier.
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
template
json
The JSON template for the registration.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
createRawTemplateRegistration(channel, tags, template, optionsOrCallback, callback)
Creates a custom template registration. Use this method to have full control on the template format.Parameters
Name
Type
Argument
Description
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
template
json
The JSON template for the registration.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
pnsCredentialName
object
<optional>
The pns credentials to use.
headers
object
<optional>
The mpns headers to include.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
createTileRegistration(channel, tags, template, options, callback)
Creates a registration with a Tile template. For more information see Windows Phone Tile template.Parameters
Name
Type
Argument
Description
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
template
object
The registration template.
Name
Type
Description
backgroundImage
string
The URI of the background image for the tile.
count
string
The number that appears on the tile.
title
string
The title text of the tile.
backBackgroundImage
string
The URI of the image that is shown on the backside of the tile.
backTitle
string
The title text for the backside of the tile.
backContent
string
The text for the backside of the tile.
id
string
The ID of a related, secondary tile.
options
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
createToastRegistration(channel, tags, template, options, callback)
Creates a new registration with a toast template. For more information, see Toasts for Windows Phone 8.Parameters
Name
Type
Argument
Description
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
template
object
The body template of the registration.
Name
Type
Description
text1}
string
Value of the Text1 element.
text2
string
Value of the Text2 element.
param
string
Optional parameters supplied to the toast. (Only for Windows Phone version 7.5 or later.)
lang
string
Value of the language of the binding element.
options
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
listRegistrationsByChannel(channel, optionsOrCallback, callback)
Retrieves registrations by channel URI.Parameters
Name
Type
Argument
Description
channel
string
The device channel URI.
optionsOrCallback
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, targetName, notificationClass, optionsOrCallback, callback)
Sends a custom MPNS notification. Use this method if you want to have full control on the payload.Parameters
Name
Type
Argument
Description
tags
array | string
A single tag, tag expression, or array of tags.
payload
string
The XML payload for the message.
targetName
string
The target name.
notificationClass
string
The notification class.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
A JSON object that specifies the success and error callback functions.
sendFlipTile(tags, payload, options, callback)
Sends a flip Tile notification. (Only Windows Phone version 7.8 or later.)Parameters
Name
Type
Argument
Description
tags
array | string
Comma-separated list or array of tag identifiers.
payload
object
The message payload.
Name
Type
Description
backgroundImage
string
The URI of the background image for the tile.
count
string
The number that appears on the tile.
title
string
The title text of the tile.
backBackgroundImage
string
The URI of the image that is shown on the backside of the tile.
backTitle
string
The title text for the backside of the tile.
backContent
string
The text for the backside of the tile.
id
string
The ID of a related, secondary tile.
smallBackgroundImage
string
The URI for the background image for the tile when it is reduced to its small size.
wideBackgroundImage
string
The URI for the background image for the tile when it is expanded to its wide size.
wideBackContent
string
Content for the back tile when the tile is expanded to its wide size.
wideBackBackgroundImage
string
The URI for the image to be on the backside of the tile when the tile is expanded to its wide size.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
A JSON object that specifies the success and error callback functions.
sendTile(tags, payload, optionsOrCallback, callback)
Sends a Tile notification. For more information see Windows Phone Tile template.Parameters
Name
Type
Argument
Description
tags
array | string
Comma-separated list or array of tag identifiers.
payload
object
The message payload.
Name
Type
Description
backgroundImage
string
The URI of the background image for the tile.
count
string
The number that appears on the tile.
title
string
The title text of the tile.
backBackgroundImage
string
The URI of the image that is shown on the backside of the tile.
backTitle
string
The title text for the backside of the tile.
backContent
string
The text for the backside of the tile.
id
string
The ID of a related, secondary tile.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
A JSON object that specifies the success and error callback functions.
sendToast(tags, payload, options, callback)
Sends a Toast notification. For more information, see Toasts for Windows Phone 8.Parameters
Name
Type
Argument
Description
tags
array | string
Comma-separated list or array of tag identifiers.
payload
object
The message payload.
Name
Type
Description
text1}
string
Value of the Text1 element.
text2
string
Value of the Text2 element.
param
string
Optional parameters supplied to the toast. (Only for Windows Phone version 7.5 or later.)
lang
string
Value of the language of the binding element.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
A JSON object that specifies the success and error callback functions.
updateFlipTileRegistration(registrationId, channel, tags, template, optionsOrCallback, callback)
Updates an existing registration with a flip Tile template. (Only supported for Windows Phone version 7.8 or later.)Parameters
Name
Type
Argument
Description
registrationId
string
The registration identifier.
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
template
object
The registration template.
Name
Type
Description
backgroundImage
string
The URI of the background image for the tile.
count
string
The number that appears on the tile.
title
string
The title text of the tile.
backBackgroundImage
string
The URI of the image that is shown on the backside of the tile.
backTitle
string
The title text for the backside of the tile.
backContent
string
The text for the backside of the tile.
id
string
The ID of a related, secondary tile.
smallBackgroundImage
string
The URI for the background image for the tile when it is reduced to its small size.
wideBackgroundImage
string
The URI for the background image for the tile when it is expanded to its wide size.
wideBackContent
string
Content for the back tile when the tile is expanded to its wide size.
wideBackBackgroundImage
string
The URI for the image to be on the backside of the tile when the tile is expanded to its wide size.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
updatesRawTemplateRegistration(registrationId, channel, tags, template, optionsOrCallback, callback)
Updates a raw template registration.Parameters
Name
Type
Argument
Description
registrationId
string
The registration identifier.
channel
string
The device channel URI.
tags
string | array
The tags for the registration.
template
json
The template for the registration.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
etag
object
<optional>
The etag to include.
callback
object
A JSON object that specifies the success and error callback functions.
updatesToastRegistration(registrationId, channel, tags, template, options, callback)
Updates an existing template registration with a new toast template. For more information, see Toasts for Windows Phone 8.Parameters
Name
Type
Argument
Description
registrationId
string
The registration identifier.
channel
string
The device channel URI.
tags
string | array
The tags for the registration.
template
object
The body template of the registration.
Name
Type
Description
text1}
string
Value of the Text1 element.
text2
string
Value of the Text2 element.
param
string
Optional parameters supplied to the toast. (Only for Windows Phone version 7.5 or later.)
lang
string
Value of the language of the binding element.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
A JSON object that specifies the success and error callback functions.
updateTileRegistration(registrationId, channel, tags, template, optionsOrCallback, callback)
Updates an existing registration with a Tile template. For more information see Windows Phone Tile template.Parameters
Name
Type
Argument
Description
registrationId
string
The registration identifier.
channel
string
The device channel URI.
tags
string | array
A single tag or array of tags (comma-separated list, no spaces).
template
object
The registration template.
Name
Type
Description
backgroundImage
string
The URI of the background image for the tile.
count
string
The number that appears on the tile.
title
string
The title text of the tile.
backBackgroundImage
string
The URI of the image that is shown on the backside of the tile.
backTitle
string
The title text for the backside of the tile.
backContent
string
The text for the backside of the tile.
id
string
The ID of a related, secondary tile.
optionsOrCallback
object
<optional>
The request options or callback.
Name
Type
Argument
Description
headers
object
<optional>
The mpns headers to include.
callback
object
<optional>
A JSON object that specifies the success and error callback functions.
Remarks
The mpns object is used to send push notifications to Windows Phone 8 and Windows Phone 8.1 Silverlight apps. To send push notifications to a Windows Phone Store 8.1 app, you must use the wns object. MPNS is not supported by Notification Hubs for Windows Phone Store 8.1 apps.
For an example of how to send push notifications from your mobile service to a Windows Phone 8 app, see Add push notifications to your Mobile Services app.
Mobile Services doesn’t require you to register your app with MPNS to enable authenticated usage. Because of this, you cannot send more than 500 messages per user each day by using MPNS.
Example
The following script uses the mpns object to send flip tile notifications to a Windows Phone 8 app.
function insert(item, user, request) {
// Define a payload for the Windows Phone toast notification.
var payload = '<?xml version="1.0" encoding="utf-8"?>' +
'<wp:Notification xmlns:wp="WPNotification"><wp:Toast>' +
'<wp:Text1>New Item</wp:Text1><wp:Text2>' + item.text +
'</wp:Text2></wp:Toast></wp:Notification>';
request.execute({
success: function() {
// If the insert succeeds, send a notification.
push.mpns.send(null, payload, 'toast', 22, {
success: function(pushResponse) {
console.log("Sent push:", pushResponse);
request.respond();
},
error: function (pushResponse) {
console.log("Error Sending push:", pushResponse);
request.respond(500, { error: pushResponse });
}
});
}
});
}
See Also
Mobile Services JavaScript (Node.js) backend library
apns object
gcm object
mpns object
wns object