瀏覽代碼

feature: 处理ios连接mqtt问题

Damon 7 月之前
父節點
當前提交
8fb58f79e6
共有 1 個文件被更改,包括 20 次插入24 次删除
  1. 20 24
      app.js

+ 20 - 24
app.js

@@ -4,10 +4,10 @@ import strings from './utils/strings';
 import store from './utils/store.js';
 import store from './utils/store.js';
 //连接的服务器域名
 //连接的服务器域名
 // const host = 'wxs://mqtt.test.radio1964.com';
 // const host = 'wxs://mqtt.test.radio1964.com';
-const host = 'wxs://mqtt.ssl.keepradioon.net:8884'
-
-// const host = 'wxs://mqtt.test.radio1964.com:8884';
 // const host = 'wxs://mqtt.ssl.keepradioon.net:8884'
 // const host = 'wxs://mqtt.ssl.keepradioon.net:8884'
+
+const iosHost = 'wxs://mqtt.test.radio1964.com:8884';
+const androidHost = 'wxs://mqtt.ssl.keepradioon.net:8884'
 App({
 App({
   globalData: {
   globalData: {
     userInfo: null,
     userInfo: null,
@@ -31,6 +31,7 @@ App({
     // 设备列表,跟app同步字段
     // 设备列表,跟app同步字段
     classifyProducts: [],
     classifyProducts: [],
     //MQTT连接的配置
     //MQTT连接的配置
+    host: iosHost,
     options: {
     options: {
       clientId: "wx_" + parseInt(Math.random() * 100 + 800, 10),
       clientId: "wx_" + parseInt(Math.random() * 100 + 800, 10),
       reconnectPeriod: 1000, //1000毫秒,两次重新连接之间的间隔
       reconnectPeriod: 1000, //1000毫秒,两次重新连接之间的间隔
@@ -54,12 +55,25 @@ App({
     if (!strings.isEmpty(classifyProducts)) {
     if (!strings.isEmpty(classifyProducts)) {
       that.globalData.classifyProducts = classifyProducts;
       that.globalData.classifyProducts = classifyProducts;
     }
     }
+    //自定义导航栏 获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度)
+    const res = wx.getSystemInfoSync(); // 获取系统信息
+    /// android ios
+    const platform = res.platform; // 获取平台类型
+    if (platform === 'android') {
+      that.globalData.host = androidHost;
+    }
+
+    let custom = wx.getMenuButtonBoundingClientRect();
+    that.globalData.navBarHeight = res.statusBarHeight + custom.height + (custom.top - res.statusBarHeight) * 2;
+    that.globalData.MenuButtonheight = custom.height;
+    that.globalData.MenuButtonTop = custom.top;
+    // var platform = res.platform;
+    // that.globalData.isIOS = platform == "ios";
+    // that.globalData.isAndroid = platform == "android";
 
 
     ///显示界面
     ///显示界面
     wx.onAppShow(() => {
     wx.onAppShow(() => {
-      console.log("gadsfasdfaf==22==");
       if (!(that.globalData.client && that.globalData.client.connected)) {
       if (!(that.globalData.client && that.globalData.client.connected)) {
-        console.log("gadsfasdfaf==333==");
         that.connect();
         that.connect();
       }
       }
     });
     });
@@ -70,20 +84,6 @@ App({
       //   that.globalData.client.end(true);
       //   that.globalData.client.end(true);
       // };
       // };
     });
     });
-
-    // that.getBluetoothStatus();
-    //自定义导航栏 获取设备顶部窗口的高度(不同设备窗口高度不一样,根据这个来设置自定义导航栏的高度)
-    wx.getSystemInfo({
-      success: (res) => {
-        let custom = wx.getMenuButtonBoundingClientRect();
-        that.globalData.navBarHeight = res.statusBarHeight + custom.height + (custom.top - res.statusBarHeight) * 2;
-        that.globalData.MenuButtonheight = custom.height;
-        that.globalData.MenuButtonTop = custom.top;
-        // var platform = res.platform;
-        // that.globalData.isIOS = platform == "ios";
-        // that.globalData.isAndroid = platform == "android";
-      }
-    });
   },
   },
 
 
   onShow: function () {
   onShow: function () {
@@ -96,15 +96,11 @@ App({
   connect() {
   connect() {
     var that = this;
     var that = this;
     var options = that.globalData.options;
     var options = that.globalData.options;
-    console.log("gadsfasdfaf==444==");
+    var host = that.globalData.host;
     that.globalData.client = mqtt.connect(host, options);
     that.globalData.client = mqtt.connect(host, options);
-    console.log("gadsfasdfaf==555==" + that.globalData.client);
-    console.log("gadsfasdfaf==aaaa==" + JSON.stringify(that.globalData.client));
-    console.log("gadsfasdfaf==666==" + that.globalData.client.connected);
 
 
     // 设备连接
     // 设备连接
     that.globalData.client.on('connect', () => {
     that.globalData.client.on('connect', () => {
-      console.log("gadsfasdfaf==777==");
       var pages = getCurrentPages();
       var pages = getCurrentPages();
       var length = pages.length;
       var length = pages.length;
       var currentPage = pages[length - 1];
       var currentPage = pages[length - 1];