我正在尝试开始使用 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。我在 Google Android Emulator 中运行该应用程序。
编辑:我尝试使用 Postman 调用注册端点:https://myservice.azure-mobile.net/push/registrations?platform=gcm&deviceId=
如果我做一个 GET,我得到 [] 作为响应,如果我做一个 POST,我得到 404
最佳答案
终于修复了 - 我没有安装 Cordova 白名单插件!
在调试到 MobileServices.Web.js 并看到与 Postman 成功的完全相同的请求在 Android 模拟器中失败后,我意识到。
关于azure-mobile-services - 适用于 Cordova 的 Azure 移动服务/VS 工具 - 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34139378/