我正在尝试使用Azure移动服务和Apache Cordova的Visual Studio工具。 (https://msdn.microsoft.com/en-gb/magazine/dn879353.aspx)
我想将移动服务用于推送通知。我已经使用Node后端和TodoItem表创建了该服务。我也设置了GCM。
但是,在尝试注册模板时,我收到404 Not Found错误:
var GCM_SENDER_ID = 'MY_GCM_ID';
mobileServiceClient = new WindowsAzure.MobileServiceClient(
"MY_URL",
"MY_API_KEY"
);
pushNotification = PushNotification.init({
"android": { "senderID": GCM_SENDER_ID }
});
pushNotification.on('registration', function (data) {
var handle = data.registrationId; //This appears to be set alright
var platform = device.platform; // This is 'Android'
if (platform == 'android' || platform == 'Android') {
var template = '{ "data" : {"message":"$(message)"}}';
mobileServiceClient.push.gcm.registerTemplate(handle, 'myTemplate', template, null);
});
最后一行给了我404.我正在谷歌Android模拟器中运行该应用程序。
编辑:我尝试使用Postman调用注册终结点:https://myservice.azure-mobile.net/push/registrations?platform=gcm&deviceId=
如果我做了GET,我得到[]作为回复,如果我做了一个POST,我得到404
答案 0 :(得分:2)
最后解决了 - 我没有安装Cordova Whitelist Plugin!
我在调试MobileServices.Web.js之后意识到并且看到与Postman成功完全相同的请求在Android模拟器中失败了。