【问题标题】:Has anyone used Firebase Cloud Messaging in Appcelerator?有人在 Appcelerator 中使用过 Firebase 云消息传递吗?
【发布时间】:2016-06-03 15:19:10
【问题描述】:

Google 将其 GCM(Google Cloud Messaging)更改为 FCM(Firebase Cloud Messaging)。我应该怎么做才能将它与 Appcelerator 应用程序集成? 我在市场上发现了很多模块,但我认为它们只适用于 GCM。

有人试过合并吗?

【问题讨论】:

  • 嘿kreatywny,你解决了吗?

标签: firebase appcelerator appcelerator-titanium firebase-cloud-messaging


【解决方案1】:

我目前正在使用 FCM 和一个名为 Ti.Goosh 的模块。它工作得非常好,我可以用它向网络浏览器和 Android 设备发送推送通知。 https://github.com/caffeinalab/ti.goosh

【讨论】:

  • 接收 Firebase 推送通知也适用于我使用这个出色的模块和 Titanium SDK 6.1.1
  • 我在我的应用程序中实现了 Ti.goosh 并且我正在获取设备令牌,但不幸的是,如果我从 firebase 发送通知,我无法在我的应用程序中得到它。此外,我找不到我的 firebase 服务器密钥应该添加到谷歌开发者控制台的位置以将我的应用程序与 firebase 链接。我在 google 开发人员控制台 API 中创建了一个新项目,并获得了一个添加到 tiapp.xml 的项目编号。任何人都可以在这方面帮助我。
【解决方案2】:

创建一个带有一些 Firebase 功能的 html,在我的例子中,我们需要在地理无线电上找到一些车辆

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Firebase</title>
        <!-- Firebase -->
        <script src="firebase.js"></script>
        <!-- GeoFire -->
        <script src="geofire.min.js"></script>
    </head>
    <body style="margin:0;padding:0;border:0;">
        <script type="text/javascript">
            var markers = new Array();
            var markersArray = [];
            var driverInvitations;
            var diverInvited;

            Ti.App.addEventListener('firebase:init', function(e) {
                Ti.API.info('Geofire init');
                Ti.API.info(e);
                Ti.API.info('latitude :'+e.latitude);
                Ti.API.info('longitude :'+e.longitude);

                var latitude = parseFloat(e.latitude);
                var longitude = parseFloat(e.longitude);

                // Set the center
                var center = [latitude, longitude];
                // Query radius
                var radiusInKm = 0;
                // Get a reference to the Firebase public transit open data set
                var transitFirebaseRef = new Firebase("https://xxx.firebaseio.com/");
                // Create a new GeoFire instance, pulling data from the public transit data
                var geoFire = new GeoFire(transitFirebaseRef.child("_geofire"));
                /*************/
                /*  GEOQUERY */
                /*************/
                // Keep track of all of the vehicles currently within the query
                var vehiclesInQuery = {};
                // Create a new GeoQuery instance
                var geoQuery = geoFire.query({
                    center : center,
                    radius : radiusInKm
                });

                geoQuery.on("ready", function() {
                  Ti.API.info("GeoQuery has loaded and fired all other events for initial data");
                  Ti.App.fireEvent('fbController:selectDriver');
                });

                /* Adds new vehicle markers to the map when they enter the query */
                geoQuery.on("key_entered", function(vehicleId, vehicleLocation) {
                    Ti.API.info('Geofire enter driver, id ' + vehicleId + ', on location ' + vehicleLocation);

                    var latitude = vehicleLocation[0];
                    var longitude = vehicleLocation[1];

                    Ti.App.fireEvent('fbController:addMarker', {
                        id : vehicleId,
                        latitude : latitude,
                        longitude : longitude
                    });

                });
                /* Moves vehicles markers on the map when their location within the query changes */
                geoQuery.on("key_moved", function(vehicleId, vehicleLocation) {
                    Ti.API.info('Geofire move driver, id ' + vehicleId + ', moved to : ' + vehicleLocation);

                    var latitude = vehicleLocation[0];
                    var longitude = vehicleLocation[1];

                    Ti.App.fireEvent('fbController:moveMarker', {
                        id : vehicleId,
                        latitude : latitude,
                        longitude : longitude
                    });

                });
                /* Removes vehicle markers from the map when they exit the query */
                geoQuery.on("key_exited", function(vehicleId) {
                    Ti.API.info('Geofire exited driver, id ' + vehicleId);

                    Ti.App.fireEvent('fbController:removeMarker', {
                        id : vehicleId
                    });
                });

            });

        </script>
    </body>
</html>

然后在视图窗口中,我们将 html 添加到容器视图中

var webview = Ti.UI.createWebView({
    url: Ti.Filesystem.resourcesDirectory + '/webview/firebase/index.html',
    width: 0,
    height: 0,
    top: 0,
    left: 0,
    visible: false
});

webview.addEventListener('load', function() {
    Ti.App.fireEvent('firebase:init', {
        latitude : latitude,
        longitude : longitude
    });
});

$.container.add(webview);

创建一些事件以与 Firebase Webview 进行通信

var Map = require('ti.map');
var mapview;
var annotations = [];

Ti.App.addEventListener('fbController:addMarker', function(e) {
    Ti.API.info('Firebase add marker: ' + e.id);

    annotations[e.id] = Map.createAnnotation({
        latitude: e.latitude,
        longitude: e.longitude,
        image: '/images/icon-car.png'
    });

    if (Ti.App.Properties.getBool('locationEnabled') == true) {
        mapview.addAnnotation(annotations[e.id]);
    } else {

    }
});

Ti.App.addEventListener('fbController:moveMarker', function(e) {
    Ti.API.info('Firebase move marker: ' + e.id);

    annotations[e.id].setLatitude(e.latitude);
    annotations[e.id].setLongitude(e.longitude);
});

Ti.App.addEventListener('fbController:removeMarker', function(e) {
    Ti.API.info('Firebase remove marker: ' + e.id);
    if (Ti.App.Properties.getBool('locationEnabled') == true) {
        mapview.removeAnnotation(annotations[e.id]);
        delete annotations[e.id];
    }
}); 

任何你需要的都可以问我,我在一个应用程序上使用它并且运行良好,尝试每天改进,但是通过这个设置我们完成了工作:),希望这会有所帮助,问候

【讨论】:

  • 我认为您在谈论不同的事情。我的问题是关于用于传递通知的FCM (Firebase Cloud Messaging)。您谈到了带有 Javascript API 的 Firebase,可以在 webview 中使用。
  • 我意识到为时已晚:P,让我用 FCM 尝试一些东西,我会给你反馈
  • 你找到办法了吗?
【解决方案3】:

我在我的 Android 应用中这样做:

  1. 安装模块 ln.vanvianen.android.gcm
  2. 在alloy.js 中创建实例:var FCM = require('actions/gcm');// pub/sub
  3. app/lib/actions/gcm.js 中创建模块和逻辑实例以与 fcm 交互。
  4. 当我在 gcm.js 上使用 Promise 时,在alloy.js 中链接 bluebird 库:var Promise = require('bluebird/bluebird');
  5. 运行我的应用程序:appc run -p android -T device
  6. 测试运行 CURL 命令或使用 firebase 通知控制台:https://console.firebase.google.com/project/your-project-name/notification Firebase Notification Console example

适用于我:sdk-version 5.5.0.GA

【讨论】:

    猜你喜欢
    • 2019-01-23
    • 1970-01-01
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 2021-06-30
    • 1970-01-01
    • 2016-10-19
    相关资源
    最近更新 更多