我正在创建一个 cordova 项目并使用 azure 移动应用程序 + 通知中心服务。 在 cordova 项目中,我添加了“cordova-plugin-ms-azure-mobile-apps”和“phonegap-plugin-push”插件,但是在运行项目时出现错误:
Failed to load resource: the server responded with a status of 404 - Cannot GET /push/installations/xxxxx(it's a guid string)
设置细节:
phonegap-plugin-push : version="1.7.2" cordova-plugin-ms-azure-mobile-apps : version="2.0.0-beta5" dev tool : visual studio 2015
var azureClient = new WindowsAzure.MobileServiceClient('http://xxxxxx.azurewebsites.net');
//PushNotification.
var push = PushNotification.init({
android: {
senderID: "xxx895803xxxx"
},
ios: {
alert: "true",
badge: "true",
sound: "true",
},
windows: {}
});
push.on('registration', function (data) {
azureClient.push.register('gcm', data.registrationId);
});
push.on('notification', function (data, d2) {
alert('Push Received: ' + data.message);
});
WindowsAzure.MobileServiceClient
是 cordova-plugin-ms-azure-mobile-apps
连接 Azure 移动应用程序和 azureClient.push.register
的插件函数将调用 executeRequest
在 MobileServices.Cordova.js
中发挥作用(cordova-plugin-ms-azure-mobile-apps
插件)
function executeRequest(client, method, pushChannel, content, installationId, callback) {
Validate.isString(pushChannel, 'pushChannel');
Validate.notNullOrEmpty(pushChannel, 'pushChannel');
var headers = { 'If-Modified-Since': 'Mon, 27 Mar 1972 00:00:00 GMT' };
headers[constants.apiVersionHeaderName] = constants.apiVersion;
client._request(
method,
'push/installations/' + encodeURIComponent(installationId),
content,
null,
headers,
callback
);
}
最佳答案
这似乎与移动应用程序或通知中心没有直接关系,而是 Cordova 配置问题。
尝试以下链接之一或 just search :
- PhoneGap “Failed to load resource: the server responded with a status of 404 (Not Found)”
- Failed to load resource: the server responded with a status of 404 (Not Found) ripple.js
- Apache Cordova: “Failed to load resource: the server responded with a status of 404 (Not Found)”
此外,还有关于如何 Add push notifications to your Apache Cordova app 的分步教程。 .可能有助于验证您所做的是否与教程建议的相似。
关于cordova azure 移动应用和通知中心服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38215862/