三叔
三叔
  • 发布:2016-05-17 11:24
  • 更新:2016-05-18 06:05
  • 阅读:1512

关于多平台的问题

分类:MUI

dcloud官方称是6大平台可以使用,其中包括手机浏览器。
现在我们的项目 很多和h5+绑的很死。
比如首先我们有gps定位,其次我们有本地存储读写,我们还有页面返回触发等等
针对上面三个方法,我们代码是这样写的:
gps的是:

gps: function() {  
        var androidGpsFlag = function getGEO_status() {  
            var context = plus.android.importClass("android.content.Context");  
            var locationManager = plus.android.importClass("android.location.LocationManager");  
            var main = plus.android.runtimeMainActivity();  
            var mainSvr = main.getSystemService(context.LOCATION_SERVICE);  
            //console.log(mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER));  
            return mainSvr.isProviderEnabled(locationManager.GPS_PROVIDER);  
        }  

        var iosGpsFlag = function() {  
            var CLLocationManager = plus.ios.import("CLLocationManager");  
            var authorizationStatus = CLLocationManager.authorizationStatus();  
            var gpsStatus = false;  
            switch (authorizationStatus) {  
                case 0:  
                    /// User has not yet made a choice with regards to this application  
                    break;  
                case 1:  
                    // This application is not authorized to use location services.  Due  
                    // to active restrictions on location services, the user cannot change  
                    // this status, and may not have personally denied authorization  
                    break;  
                case 2:  
                    // User has explicitly denied authorization for this application, or  
                    // location services are disabled in Settings.  
                    break;  
                case 3:  
                    gpsStatus = true;  
                    // User has granted authorization to use their location at any time,  
                    // including monitoring for regions, visits, or significant location changes.  
                    break;  
                case 4:  
                    gpsStatus = true;  
                    // User has granted authorization to use their location only when your app  
                    // is visible to them (it will be made visible to them if you continue to  
                    // receive location updates while in the background).  Authorization to use  
                    // launch APIs has not been granted.  
                    break;  
                case 5:  
                    // This value is deprecated, but was equivalent to the new -Always value.  
                    break;  
                    defalut:  
                        break;  
            }  
            return gpsStatus;  
        }  
        if (mui.os.android) {  
            return androidGpsFlag();  
        } else if (mui.os.ios) {  
            return iosGpsFlag();  
        }  
    }

很显然调用到底层了,这个肯定没法在浏览器里使用。
官方客服给出的解决方案是:
https://github.com/dcloudio/plusto/blob/master/geolocation/h5toplus.js

2.存储的使用。
if(plus.storage.getItem(saltkey)!=null){}
这个应该怎么用 用html5的sessionStorange么?还是mui里有什么兼容的方法。

3.页面返回触发方法,用户网页回跳时出发,比如登录完毕后调回某个界面触发:
var self = plus.webview.currentWebview();
var opener = self.opener();
mui.fire(opener, 'back', parame);
那在手机版里 是需要自己写代码么???还是mui提供了平滑过度

2016-05-17 11:24 负责人:无 分享
已邀请:
DCloud_heavensoft

DCloud_heavensoft

  1. 如果不涉及跨域的话,plus.storage改为localstorage,实际开发中仅存在本地页面和服务器页面同时要操作一个存储键值对才需要用plus.storage。
  2. if 一下ua吧。。。

该问题目前已经被锁定, 无法添加新回复