In uniapp, you can use the uni-imei plug-in to get the device number. The steps to use are as follows:
1. Install the uni-imei plug-in, you can directly search and install it in HBuilderX, or add the following configuration in the "App native plug-in configuration" in the manifest.json file:
"plugins": {
"uni-imei": {
"version": "1.1.0",
"provider": "uni-app.plus"
}
}
2. Introduce the uni-imei plug-in to the page that needs to obtain the device number:
import imei from '@/uni_modules/uni-imei/js_sdk/uni-imei.js';
3. Call the getImei method of the uni-imei plug-in to get the device number:
imei.getImei({
success: function (res) {
console.log(res.imei); // 获取到的设备号
}
});
It should be noted that obtaining the device ID requires user authorization, so before calling the getImei method, you need to call the requestPermission method of the uni-imei plug-in to request authorization.