首页 > 解决方案 > 在 Titanium 中实现 Ti.goosh 推送通知模块以支持 Firebase

问题描述

我在我的应用程序中实现了 Ti.goosh 模块,用于从 Firebase 发送推送通知。我按照这个 git 文档在 Google Developer Console API 中创建了一个新项目。我从那里获得了一个项目编号,并将其用作 tiapp.xml 中的“GCM 发件人 ID”。然后我在我的 index.js 控制器中添加了以下代码。

var TiGoosh = require('ti.goosh');
TiGoosh.registerForPushNotifications({


    // The callback to invoke when a notification arrives.
    callback: function(e) {
    
        var data = JSON.parse(e.data || '');
    
    },

    // The callback invoked when you have the device token.
    success: function(e) {

        // Send the e.deviceToken variable to your PUSH server
        Ti.API.log('Notifications: device token is ' + e.deviceToken);

    },

    // The callback invoked on some errors.
    error: function(err) {
        Ti.API.error('Notifications: Retrieve device token failed', err);
    }
});

当我运行应用程序时,成功块执行并且我得到了设备令牌。但我没有收到来自 firebase 的消息。我也无法理解 Firebase 中的服务器密钥和 API 密钥应包含在此模块中的何处以与我的应用程序链接。

我怎样才能理解整个事情?Titanium 中的推送通知似乎非常复杂,文档也很差。

标签: androidfirebasemodulepush-notificationtitanium

解决方案


使用此 php 脚本发送通知并确认您收到带有 ti.goosh 的数据

您需要在脚本中包含您的 api 密钥和设备令牌 (registration_ids)


推荐阅读