iOS doesn't receive push from Azure Notificati

2019-08-12 01:28发布

问题:

In my iOS app I'm trying to add push notifications via Azure Mobile Services.

I have followed this article: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-ios-get-started-push/

But my app still receive no push notifications!

In the iOS dev center I registered App ID with Dev and Production push certificates.

Added Dev certificate (.p12) to Sandbox in the Azure.

I wrote POST function

exports.post = function(request, response) {
    var text = 'You\'ve just received a push!';
    var push = request.service.push;
        push.apns.send(null, {
          alert: "Alert",
          payload: {
              inAppMessage: text
          } 
        }, {
          success: function(pushResponse) {
          console.log("Sent iOS push:", pushResponse);
          response.send(statusCodes.OK, { message : 'Push send success' });
        }, error: function(error) {
          console.log("Sent iOS push error:", error);
          response.send(statusCodes.BAD_REQUEST, { message : 'Push send error: ' + error });
        }
    });
};

In the log I'm getting this everytime:

Sent iOS push: { isSuccessful: true,
statusCode: 201,
body: '',
headers: 
{ 'transfer-encoding': 'chunked',
   'content-type': 'application/xml; charset=utf-8',
   server: 'Microsoft-HTTPAPI/2.0',
   date: 'Sat, 02 Apr 2016 18:27:42 GMT' },
md5: undefined }

Also, in the app I register for push:

if let client = self.azureClient {
    client.push.registerNativeWithDeviceToken(deviceToken, tags: nil, completion: { (error: NSError?) in
        if let error = error {
            print(error)
        }
    })
}

I'm stuck and don't know what to do to make Azure send pushes to my app.

It would be great if anyone could explain me what I'm doing wrong.

Thanks!

UPDATED

I've just found that in Notification Hub Debug tab when I try to broadcast push it shows that there is no registrations: Despite the fact that Notification Hub Monitor shows, that there was some Registration Operations and Incoming Messages:

回答1:

The alert key needs to be inside an aps object, like so:

push.apns.send(null, {
    aps: {
        alert: "Alert"
    },
    payload: {
        inAppMessage: text
    } 
}, .... );

Apple has a page on push notification payloads with more examples.

Also make sure you are running your app on a device, as the simulator can't receive notifications.

If you still aren't getting notifications, see Apple's troubleshooting page for push notifications or update your question.



回答2:

It is strange, but when I replaced Developer Push Certificate with Production Push Certificate, my app suddenly began to receive pushes! Isn't it bug of Azure? Any guess why it happens?