在我的iOS应用中,我尝试通过Azure移动服务添加推送通知。
但是我的应用仍然没有收到推送通知!
在iOS开发中心,我使用Dev和Production推送证书注册了App ID。
将Azure证书(.p12)添加到Azure中的Sandbox。
我写了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 }
此外,在app中我注册了push:
if let client = self.azureClient {
client.push.registerNativeWithDeviceToken(deviceToken, tags: nil, completion: { (error: NSError?) in
if let error = error {
print(error)
}
})
}
我已经陷入困境,并且不知道如何让Azure发送推送到我的应用。
如果有人能解释我做错了什么就会很棒。
谢谢!
已更新
我刚刚在Notification Hub Debug选项卡中发现,当我尝试广播推送时,它显示没有注册: 尽管通知中心监视器显示,但有一些注册操作和传入消息:
答案 0 :(得分:0)
警报键需要位于aps对象内,如下所示:
push.apns.send(null, {
aps: {
alert: "Alert"
},
payload: {
inAppMessage: text
}
}, .... );
Apple有page on push notification payloads个例子。
还要确保您在设备上运行应用,因为模拟器无法接收通知。
如果您仍未收到通知,请参阅Apple的troubleshooting page for push notifications或更新您的问题。
答案 1 :(得分:0)
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?