3

我正在创建一个cordova项目并使用azure移动应用+通知中心服务。 在科尔多瓦项目中,我添加了“科尔多瓦 - 插件-MS-Azure的移动应用程序”和“PhoneGap的-插件推”插件,但跑项目时,我得到一个错误:cordova azure移动应用和通知中心服务

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

错误消息PIC: enter image description here

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插件连接蔚蓝的移动应用和azureClient.push.register功能将调用MobileServices.Cordova.jscordova-plugin-ms-azure-mobile-apps插件)executeRequest功能

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 
 
    ); 
 
}

回答

0

这似乎并不直接相关移动应用程序或通知中心,而是Cordova配置问题。

可尝试以下链接的一个或just search

此外,还有一步一步的教程就如何Add push notifications to your Apache Cordova app。可能有助于验证你所做的与本教程的建议类似。

+0

谢谢,但我的情况只在移动应用程序和通知中心,我检查了科尔多瓦白名单配置,是currect。 – Ian

+0

您能解释一下“什么时候运行项目”是什么意思吗?你在什么时候收到错误信息?构建还是运行时?如果后者,那么你能粘贴失败的代码块吗? –

+0

嗨, 获取运行时错误(调试模式),发布项目到设备并使用模拟器。 – Ian

0

在您的build.gradle文件中添加以下依赖项。并再次建立。

dependencies { 
     classpath 'com.android.tools.build:gradle:1.5.0' 
     classpath 'com.android.tools.build:gradle:2.1.0' 
     classpath 'com.google.gms:google-services:3.0.0' 
    }