带有phonegapcordova的流星

带有phonegapcordova的流星,第1张

概述我正在研究流星移动应用程序(即时通讯使用 android). 即时通讯使用MetoerRider方法,本质上是phonegap应用程序启动,一旦应用程序完成启动它就会对流星应用程序执行ajax调用(“ http://myapp.meteor.com”) 我得到了流星应用程序的DOM作为回应. $.ajax({ url: __MeteorRiderConfig__.meteorUrl, 我正在研究流星移动应用程序(即时通讯使用 android).
即时通讯使用MetoerRIDer方法,本质上是phonegap应用程序启动,一旦应用程序完成启动它就会对流星应用程序执行AJAX调用(“ http://myapp.meteor.com”)

我得到了流星应用程序的DOM作为回应.

$.AJAX({      url: __MeteorRIDerConfig__.meteorUrl,cache: false,// Todo: split to method on MeteorRIDer      error: function( jqXHR,textStatus,errorThrown ) {        console.error("MeteorRIDer failure");        console.error(jqXHR,errorThrown);      },// Todo: split to method on MeteorRIDer      success: function( data,jqXHR ) {        console.log("MeteorRIDer success");        console.log(textStatus);        console.log(data);        // update URLs        data = data.replace(/(href|src|manifest)\=\"\//gm,'="' + meteorUrl + '/');          console.log(meteorUrl);        console.log(data);// get the original file location,not including any paramsphonegapLocation = window.location.href.split('.HTML')[0] + '.HTML';// it's stored in a param "page"currentMeteorPath = window.location.search.replace("?","")if(currentMeteorPath.length > 0) {  meteorUrl += currentMeteorPath.split('page=')[1]}console.log("replacing state with "+meteorUrl)window.history.replaceState({},"",meteorUrl);          // replace the document with the new document/data        document.open();        document.write(data);        document.close();        // trigger the "loaded" events (it'd be nice to do this AFTER Js has loaded        $(document).trigger('DOMContentLoaded');        $(document).trigger('load');        $(document).trigger('complete');      }    });  }

问题是我的phonegap应用程序只在wifi打开时工作,一旦我关闭wifi它停止工作,如果我启动我的phonegap应用程序当wifi关闭我仍然得到流星DOM到我的phonegap应用程序,但我不能做任何功能(登录/创建组等).

所以我开始调试我的应用程序(使用build.phonegap.com中的phonegap调试),
这是我打开wifi时得到的日志:

if(navigator.online){console.log("true")}else{console.log("false")}

日志 – > “真正”

var networkState = navigator.connection.type;        var states = {};        states[Connection.UNKNowN]  = 'UnkNown connection';        states[Connection.ETHERNET] = 'Ethernet connection';        states[Connection.WIFI]     = 'WiFi connection';        states[Connection.CELL_2G]  = 'Cell 2G connection';        states[Connection.CELL_3G]  = 'Cell 3G connection';        states[Connection.CELL_4G]  = 'Cell 4G connection';        states[Connection.NONE]     = 'No network connection';    console.log('Connection type: ' + states[networkState]);    }

日志 – > ‘WiFi连接’

Meteor.status()

日志 – >连接:是的
retryCount:0
状态:“已连接”

使用移动网络时:

if(navigator.online){    console.log("true")    }    else{    console.log("false")    }

日志 – > “真正”

var networkState = navigator.connection.type;        var states = {};        states[Connection.UNKNowN]  = 'UnkNown connection';        states[Connection.ETHERNET] = 'Ethernet connection';        states[Connection.WIFI]     = 'WiFi connection';        states[Connection.CELL_2G]  = 'Cell 2G connection';        states[Connection.CELL_3G]  = 'Cell 3G connection';        states[Connection.CELL_4G]  = 'Cell 4G connection';        states[Connection.NONE]     = 'No network connection';    console.log('Connection type: ' + states[networkState]);    }

日志 – > ‘Cell 3G连接’

Meteor.status()

日志 – >连接:错误
retryCount:1
状态:“连接”

试图做Meteor.reconnect()没有帮助,它没有工作.
当打开wifi时,当进行Meteor.disconnect()时,应用程序会断开连接,但是当尝试执行Meteor.reconnect()时,它也无法正常工作.

当切换(当应用程序工作时)要么wifi上/ wifi关闭.我失去了所有连接,甚至无法调试.

编辑:添加了离线活动

phonegapapp = {    // are we on a phonegap app?    phonegap: true,// are we testing PhoneGap or not?    test: false,// Application Constructor    initialize: function () {        this.bindEvents();    },// Bind Event Listeners    //    // Bind any events that are required on startup. Common events are:    // 'load','deviceready','offline',and 'online'.    bindEvents: function () {        document.addEventListener('deviceready',this.onDeviceReady,false);    },// deviceready Event Handler    //    // The scope of 'this' is the event. In order to call the 'receivedEvent'    // function,we must explicity call 'phonegapapp.receivedEvent(...);'    onDeviceReady: function () {        document.addEventListener("offline",this.onOffline,false);        phonegapapp.receivedEvent('deviceready');        phonegapapp.receivedEvent('offline');        if (this.test) {            $('phonegapapp-test').show();        } else {            phonegapapp.meteorRIDer();        }    },// Update DOM on a Received Event    receivedEvent: function (ID) {        console.log('Received Event: ' + ID);    },onOffline: function () {        device.exitApp();    },// Setup MeteorRIDer    meteorRIDer: function () {        MeteorRIDer.init();    }};

更新:
在另外一个流星应用程序(没有铁路由器,test.meteor.com)上测试了两部AndroID手机(v 4.1.2和v 4.3.3).记录两部手机 – Meteor.status()在使用移动网络时“连接”.但是当打开/关闭wifi时,两者都丢失了任何网络连接.

所以我把它缩小到两个可能的问题:
1.my meteor app做错了什么.
2.iron路由器

另一个检查另一个流星应用程序(使用铁路由器的应用程序)
meteor.status()记录“已连接”.
我相信失败的原因是在我的应用程序中,我不会在我的流星应用程序中看到任何错误.

新更新:
好吧所以这真的很奇怪,我已经开始了一个新的流星应用程序只是做“流星创建测试”
添加了铁路由器和更多的软件包,如下划线jquery帐户等.
然后我把它部署到流星 – 流星部署boaz.meteor,com
提示输入密码,选择我的phonegap应用程序查看其工作是否记录为Meteor.status();并得到“虚假”和“连接”

新更新:
尝试创建一个没有任何更改的应用程序或没有添加任何包或删除任何包.
也许,Meteor.status();记录“假”和“连接”

解决方法 请注册离线活动.如果设备脱机,将触发此事件的回调.在回调函数中,关闭(终止/停止/退出)应用程序.

触发离线事件的代码:

document.addEventListener("offline",onOffline,false);function onOffline() {    // Handle the offline event}

退出iphone的应用程序:navigator.device.exitApp();

退出AndroID的应用程序:device.exitApp();

这样,当连接关闭时,应用程序将关闭,并且可以再次打开.请告诉我

总结

以上是内存溢出为你收集整理的带有phonegap / cordova的流星全部内容,希望文章能够帮你解决带有phonegap / cordova的流星所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1002028.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存