iOS 没有收到来自 Azure 通知中心的推送
iOS doesn't receive push from Azure Notification Hub
在我的 iOS 应用程序中,我正在尝试通过 Azure 移动服务添加推送通知。
但我的应用程序仍然没有收到推送通知!
在 iOS 开发中心,我使用开发和生产推送证书注册了 App ID。
已将开发证书 (.p12) 添加到 Azure 中的沙箱。
我写了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 向我的应用程序发送推送。
如果有人能解释我做错了什么,那就太好了。
谢谢!
已更新
我刚刚发现,当我尝试广播推送时,在 Notification Hub Debug 选项卡中显示没有注册:
尽管 Notification Hub Monitor 显示了一些注册操作和传入消息:
警报键需要在 aps 对象内,如下所示:
push.apns.send(null, {
aps: {
alert: "Alert"
},
payload: {
inAppMessage: text
}
}, .... );
Apple 有一个 page on push notification payloads,包含更多示例。
另外请确保您 运行 您的应用在设备上,因为模拟器无法接收通知。
如果您仍然没有收到通知,请参阅 Apple 的 troubleshooting page for push notifications 或更新您的问题。
奇怪,当我用Production Push Certificate替换Developer Push Certificate时,我的应用突然开始接收推送了!这不是Azure的错误吗?猜猜为什么会这样?
在我的 iOS 应用程序中,我正在尝试通过 Azure 移动服务添加推送通知。
但我的应用程序仍然没有收到推送通知!
在 iOS 开发中心,我使用开发和生产推送证书注册了 App ID。
已将开发证书 (.p12) 添加到 Azure 中的沙箱。
我写了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 向我的应用程序发送推送。
如果有人能解释我做错了什么,那就太好了。
谢谢!
已更新
我刚刚发现,当我尝试广播推送时,在 Notification Hub Debug 选项卡中显示没有注册:
警报键需要在 aps 对象内,如下所示:
push.apns.send(null, {
aps: {
alert: "Alert"
},
payload: {
inAppMessage: text
}
}, .... );
Apple 有一个 page on push notification payloads,包含更多示例。
另外请确保您 运行 您的应用在设备上,因为模拟器无法接收通知。
如果您仍然没有收到通知,请参阅 Apple 的 troubleshooting page for push notifications 或更新您的问题。
奇怪,当我用Production Push Certificate替换Developer Push Certificate时,我的应用突然开始接收推送了!这不是Azure的错误吗?猜猜为什么会这样?