2016-04-02 95 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的細節。 –