Dışarıya aktar (0) Yazdır
Tümünü Genişlet
EN
Bu içerik dilinizde bulunmamaktadır ancak İngilizce sürümüne buradan bakabilirsiniz.
Bu konu henüz değerlendirilmedi - Bu konuyu değerlendir

push object

Updated: April 18, 2013

Provides access to objects that are used for sending push notifications to apps.

This object contains the following methods:

Methods

 

Method Type Description

apns

apns object

Returns an apns object that is used to send push notifications to an iOS app using the Apple Push Notification Service (APNS).

gcm

gcm object

Returns a gcm object that is used to send push notifications to an Android app using Google Cloud Messaging (GCM).

mpns

mpns object

Returns an mpns object that is used to send push notifications to a Windows Phone 8 app using the Microsoft Push Notification Service (MPNS).

wns

wns object

Returns a wns object that is used to send push notifications to a Windows Store app using Windows Notification Services (WNS).

The global push object is used to send push notifications. For more information, see Get started with push notifications (Windows Store/Windows Phone/iOS/Android).

The version of the wns object exposed by Mobile Services for use in scripts has the following customizations:

  • Success and error callbacks are separate and specified as properties of the options object. This is the same as other asynchronous APIs that scripts use.

  • client_id and client_secret properties of the options object are provided automatically using the configuration settings.

  • When an accessToken is obtained, it is cached in memory.

  • You can call the send* methods either with a single channel URL or with a channel array.

  • The channel URL is passed to callbacks as part of the result or error object.

  • accessToken is not passed back to the caller through the callback.

  • Only x-wns-* HTTP response headers are returned in the result or error.

The version of the mpns object exposed by Mobile Services for use in scripts has the following customizations:

  • Success and error callbacks are separate and specified as properties of the options object. This is the same as other asynchronous APIs that scripts use.

  • You can call the send* methods either with a single channel URL or with a channel array.

  • The channel URL is passed to callbacks as part of the result or error object.

The version of the gcm object exposed by Mobile Services for use in scripts has the following customizations:

  • Success and error callbacks are separate and specified as properties of the options object. This is the same as other asynchronous APIs that scripts use.

  • You can call the send* methods either with a single channel URL or with a channel array.

  • You can call the sendAdvanced method with a parameter that specifies the number of times to retry the notification.

  • The channel URL is passed to callbacks as part of the result or error object.

The following script uses the wns object to send toast notifications to a Windows Store app.


function insert(comment, user, request) { 
  request.execute({ 
    success: function() { 
      var sql = "SELECT deviceId FROM devices " + 
      "INNER JOIN posts ON devices.userId = posts.userId " + 
      "WHERE posts._id = ?"; 
      mssql.query(sql, [comment.postId], { 
        success: function(results) { 
          if(results.length > 0) { 
            push.wns.sendToastText04(results[0].deviceId, { 
              text1: comment.username + ' commented on your post!' 
            }); 
          } 
        } 
      }); 
      // Write to the response for the original request while the push notification happens in the background. 
      request.respond(); 
    } 
  }); 
}

The following script uses the mpns object to send flip tile notifications to a Windows Phone 8 app.

function insert(item, user, request) {
    request.execute({
        success: function() {
            request.respond();
            sendNotifications();
        }
    });
   function sendNotifications() {
       var channelTable = tables.getTable('Channel');
       channelTable.read({
           success: function(channels) {
               channels.forEach(function(channel) {
                   push.mpns.sendFlipTile(channel.uri, {
                       title: item.text
                   }, {
                       success: function(pushResponse) {
                           console.log("Sent push:", pushResponse);
                       }
                   });
               });
           }
       });
   }
}

The following script calls the send method of the gcm object to send a notification to an Android app.


function insert(item, user, request) { 
  request.execute({ 
      success: function() { 
            // Write to the response and then send the notification in the background
            request.respond();
            push.gcm.send(item.channel, item.text, {
                success: function(response) {
                    console.log('Push notification sent: ', response);
                }, error: function(error) {
                    console.log('Error sending push notification: ', error);
                }
             });
         }
    });
}

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

function insert(item, user, request) {
    request.execute({
        success: function() {
            // Write to the response and then send the push notification.
            request.respond();
            push.apns.send(item.deviceToken, {
                payload: { itemText: item.text, userId: user.userId } 
            });
        }
    });
}

Bunu faydalı buldunuz mu?
(1500 karakter kaldı)
Geri bildiriminiz için teşekkür ederiz
Show:
© 2014 Microsoft. Tüm hakları saklıdır.