2016-04-02 98 views
1

在我的iOS应用中,我试图通过Azure移动服务添加推送通知。iOS没有收到来自Azure通知中心的推送

我按照这篇文章:https://azure.microsoft.com/en-us/documentation/articles/mobile-services-javascript-backend-ios-get-started-push/

但我的应用程序还是没有收到推送通知!

在iOS开发中心,我注册了具有Dev和Production推送证书的App ID。

向Azure中的沙箱添加了开发人员证书(.p12)。

我写了POST功能

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 }); 
     } 
    }); 
}; 

在日志中我得到这个每次:

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 } 

此外,在应用程序我注册推:

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

我被困住了,不知道该怎么做才能让Azure发送到我的应用程序。

如果有人能解释我做错了什么,那将会很棒。

谢谢!

修订

我刚刚发现,在通知中心,调试选项卡,当我尝试播放推它表明,没有登记: enter image description here 尽管通知中心监控显示,有在一些登记工作,收到的消息: enter image description here

回答

0

这很奇怪,但是当我用生产推送证书替换了开发人员推送证书时,我的应用程序突然开始接受推送!是不是Azure的错误?任何猜测为什么会发生?

+0

很高兴你的工作!如果您正在运行TestFlight或其他临时分发,它将使用生产APN频道。如果您从Xcode运行,则它使用Developer/Sandbox通道。 –

+0

谢谢!因此,这非常奇怪,因为我正在使用XCode运行应用程序,并且可能需要使用Dev证书才能收到应用程序,但是当我将Dev证书替换为Production时,它开始运行良好。 –

0

警报关键需求是一个APS对象的内部,像这样:

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

Apple有page on push notification payloads以及更多示例。

此外,请确保您正在设备上运行您的应用程序,因为模拟器无法接收通知。

如果您还没有收到通知,请参阅Apple的troubleshooting page for push notifications或更新您的问题。

+0

谢谢你的回答! 我在设备上运行应用程序。 我刚刚添加了一些关于Notification Hub Debug的细节。 –