【问题标题】:cordova azure mobile apps & notification hub service科尔多瓦天蓝色移动应用和通知中心服务
【发布时间】:2016-11-08 00:35:04
【问题描述】:

我正在创建一个 cordova 项目并使用 azure 移动应用 + 通知中心服务。 在 cordova 项目中,我添加了“cordova-plugin-ms-azure-mobile-apps”和“phonegap-plugin-push”插件,但是在运行项目时出现错误:

加载资源失败:服务器响应状态为 404 - 无法获取 /push/installations/xxxxx(这是一个 guid 字符串)

设置详情:

phonegap-plugin-push : version="1.7.2" cordova-plugin-ms-azure-mobile-apps : 版本="2.0.0-beta5" 开发工具: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 函数将调用MobileServices.Cordova.js 中的executeRequest 函数(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 cordova-plugins azure-mobile-services visual-studio-cordova azure-notificationhub


    【解决方案1】:

    这似乎与移动应用或通知中心没有直接关系,而是 Cordova 配置问题。

    尝试以下链接之一或just search:

    此外,还有一个关于如何Add push notifications to your Apache Cordova app 的分步教程。可能有助于验证您所做的是否与教程建议的相似。

    【讨论】:

    • 谢谢,但我的情况只在移动应用和通知中心,我检查了科尔多瓦白名单配置,是正确的。
    • 您能解释一下“运行项目时”的确切含义吗?您在什么时候收到错误消息?构建还是运行时?如果是后者,那么你能粘贴失败的代码块吗?
    • 您好,运行时出现错误(调试模式),将项目发布到设备并使用模拟器。
    • 您可以通过debugging guidelinesdiagnostics guidelines 看看是否可以找到解决方案吗?如果不了解有关您的设置的更多详细信息,仍然很难判断。
    • 偶然发现了同样的问题。有什么解决办法吗?
    【解决方案2】:

    在您的 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'
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      • 2017-09-06
      • 1970-01-01
      • 2019-09-28
      • 2018-08-15
      • 2015-11-24
      • 2016-04-22
      相关资源
      最近更新 更多