Wechat applet acquisition is android or ios, wechat applet-mobile operating system and wechat version judgment

First of all, to determine the current user's WeChat version and whether it is Android or iOS, the method wx.getSystemInfo() must be called. Official document: https://developers.weixin.qq.com/miniprogram/dev/api/system/system-info/ wx.getSystemInfo.html

wx.getSystemInfo({
    
     success:function(res) {
    
     } })  

In the successful success method, res contains relevant information, and the next step is to make a judgment:

1. WeChat version judgment method

compareVersion(v1, v2) {
    
    
    v1 = v1.split('.')
    v2 = v2.split('.')
    var len = Math.max(v1.length, v2.length)
    while(v1.length
    	v1.push('0')
    }
    while(v2.length
    	v2.push('0')
    }
    for(var i = 0; i
        var num1 = parseInt(v1[i])
        var num2 = parseInt(v2[i])
        if (num1 > num2) {
    
    
        	return 1
        } else if (num1 < num2) {
    
    
        	return -1
        }
    }
    return 0
}

Wechat version judgment is very important, which involves version compatibility. It is more related to the functional integrity of the entire applet.

2. Operating system judgment

res.system.indexOf('iOS') > -1 是iOS 
res.system.indexOf('android') >-1 是安卓 

Special functions can be realized according to different mobile phone operating systems.

Guess you like

Origin blog.csdn.net/weixin_45828554/article/details/130611634