当前位置: 首页 > wzjs >正文

公司网站大全中国免费网站服务器2020

公司网站大全,中国免费网站服务器2020,宁波做网站的大公司,新素材网站历经波折三次成功上岸! 三次经历简单絮叨一下:使用uniAppvue开发的微信小程序,使用蓝牙连接打印机,蓝牙所有的接口都是插件中封装的,用的插件市场中的这个: dothan-lpapi-ble ;所以&#xff0c…

历经波折三次成功上岸!

三次经历简单絮叨一下:使用uniApp+vue开发的微信小程序,使用蓝牙连接打印机,蓝牙所有的接口都是插件中封装的,用的插件市场中的这个: dothan-lpapi-ble ;所以,开发中,主要是看插件文档中使用的API。

首次上线

情况说明: 首次上线微信小程序:直接初始化实例,调用的插件API,测试环境成功连接打印,就上线了。

结果

客户手机一直搜索不到打印机,根据经验发现没执行实例的代码;
想到授权蓝牙也没自动弹框提示,小程序设置中也没有蓝牙开启设置;

问题定位:

那就问 deepseeek 开干呗!
1. 可能是用户手机 鸿蒙系统 问题:在系统设置中找到应用管理,找到微信,然后打开微信的权限管理,查看 附近设备的权限 - 开启(反复开关)。

插件市场遇到的特殊情况
2. 显示授权:必要的权限声明
3. 检查manifest.json配置
4. 微信小程序发版后台 - 设置 - 基本设置 - 服务内容声明 - 用户隐私保护指引 - 添加(蓝牙、微信信息收集)

二次上线

情况说明: 二次上线微信小程序:提交审核是其他同事在做,正常提交

结果

客户手机一直搜索不到打印机,根据经验发现没执行实例的代码;
线上环境用户还是没有触发授权蓝牙、位置信息提示;
审核没通过

问题定位:

1. 提交审核时勾选了:未采集用户隐私
2. 亲自提审、加图片、视频辅佐

三次上线

情况说明:审核通过

结果

线上成功授权、成功搜索打印机!

成功版本代码

manifest.json配置

"mp-weixin": {"appid": "...",//  添加..."permission": {"scope.bluetooth": {"desc": "用于连接蓝牙设备"},"scope.userLocation": {"desc": "你的位置信息将用于蓝牙设备连接"}},"requiredPrivateInfos": ["getLocation"]},

授权提示 - deepseek友情提供

// 使用-获取蓝牙权限
await this.bringBluetoothRight();// 方法 methods: 
bringBluetoothRight() {let _this = this;return new Promise((resolve, reject) => {uni.getSetting({success: async (res) => {try {console.log(res, 'res')// 1. 同时检查蓝牙和位置权限const needBluetooth = !res.authSetting['scope.bluetooth'];const needLocation = !res.authSetting['scope.userLocation'];if (!needBluetooth && !needLocation) {// 已有全部权限return resolve(await _this.wechatBluetoothAuthUtils());}// 2. 显示预授权提示(合并说明)await _this.showPreAuthorizeModal('需要蓝牙和位置权限','连接打印机需要以下权限:\n\n1. 蓝牙权限 - 用于设备配对\n2. 位置权限 - 用于搜索设备');// 3. 按顺序请求权限if (needBluetooth) {await _this.requestPermission('scope.bluetooth', '蓝牙');}if (needLocation) {await _this.requestPermission('scope.userLocation', '位置');}// 4. 验证权限获取结果const currentSettings = await _this.getSettingWithRetry();console.log(currentSettings, 'currentSettings')if ((!needBluetooth || currentSettings['scope.bluetooth']) &&(!needLocation || currentSettings['scope.userLocation'])) {console.log('.......')resolve(await _this.wechatBluetoothAuthUtils());} else {console.log('1111111')// 5. 有权限未被授予,引导去设置页await _this.showGoSettingModal();const finalSettings = await _this.getSettingWithRetry();if ((!needBluetooth || finalSettings['scope.bluetooth']) &&(!needLocation || finalSettings['scope.userLocation'])) {resolve(await _this.wechatBluetoothAuthUtils());} else {reject(new Error('权限未完全授予'));}}} catch (error) {reject(error);}},fail: reject});});
},
// 新增:带重试的获取设置
getSettingWithRetry(retry = 2) {return new Promise((resolve, reject) => {const tryGet = (attempt) => {uni.getSetting({success: resolve,fail: attempt > 0 ?() => setTimeout(() => tryGet(attempt - 1), 500) : reject});};tryGet(retry);});
},// 改进:通用权限请求方法
requestPermission(scope, permissionName) {let _this = this;// 添加最大重试次数控制const MAX_RETRY = 1; // 最多重试1次(即总共2次机会)return new Promise((resolve, reject) => {const tryAuthorize = (retryCount = 0) => {uni.authorize({scope,success: resolve,fail: async () => {// 第一次拒绝时显示提示,后续直接引导去设置页if (retryCount < MAX_RETRY) {const confirmed = await _this.showPreAuthorizeModal(`${permissionName}权限被拒绝`,`需要${permissionName}权限才能连接打印机,是否重新授权?`,'重新授权','取消');if (confirmed) {tryAuthorize(retryCount + 1); // 增加重试计数return;}}// 达到最大重试或用户取消,引导去设置页const goSetting = await _this.showPreAuthorizeModal('权限不足',`需要${permissionName}权限才能使用打印机功能,是否去设置页开启?`,'去设置','暂不开启');if (goSetting) {uni.openSetting({success: (res) => {res.authSetting[scope] ? resolve() :reject(new Error(`用户未授权${permissionName}权限`));},fail: () => reject(new Error('打开设置页失败'))});} else {reject(new Error(`用户取消${permissionName}权限授权`));}}});};tryAuthorize(); // 开始首次授权尝试});
},
// 改进:预授权弹窗(返回Promise<boolean>)
showPreAuthorizeModal(title, content) {return new Promise((resolve) => {uni.showModal({title,content,confirmText: '继续',cancelText: '取消',success: (res) => {resolve(!!res.confirm);},fail: () => resolve(false)});});
},// 改进:去设置页弹窗
showGoSettingModal() {return this.showPreAuthorizeModal('需要权限','需要前往设置页手动开启权限,是否现在去设置?').then((confirm) => {if (confirm) {return new Promise((resolve) => {uni.openSetting({success: resolve,fail: resolve});});}return Promise.reject(new Error('用户取消设置'));});
},wechatBluetoothAuthUtils() {let _this = this;const {bluetoothEnabled,platform} = uni.getSystemInfoSync();console.log(bluetoothEnabled,platform)// 设备为IOS时,微信蓝牙是否开启if (platform === 'ios') {return new Promise((resolve, reject) => {// 初始化蓝牙模块(用openBluetoothAdapter 方法解决部分ios设备,授权蓝牙失败的问题)uni.openBluetoothAdapter({success: () => {// 开启蓝牙功能 =》 初始化拾果sdkresolve(true);},fail: (openBlueFail) => {if (openBlueFail.state === 3) {// 说明微信应用蓝牙未授权uni.showModal({content: '检测到您未允许微信访问手机蓝牙权限,是否打开系统设置?',showCancel: false,confirmText: '前往设置',success: () => {// 跳转微信应用权限uni.openAppAuthorizeSetting();},});} else if (openBlueFail.state === 4) {// 说明系统蓝牙未开启uni.showModal({content: '蓝牙设置 - 小程序需要通过蓝牙搜索和连接设备,请确认手机蓝牙功能是否已开启?',showCancel: false,confirmText: '我已开启',success: async () => {const {bluetoothEnabled,platform} = uni.getSystemInfoSync();if (bluetoothEnabled) {// 开启蓝牙功能resolve(true);} else {uni.showToast({icon: 'none',title: '手机蓝牙未开启'})}},});}},});});} else {return new Promise(function(resolve, reject) {// andriodif (!bluetoothEnabled) {// 说明系统蓝牙未开启uni.showModal({content: '蓝牙设置 - 小程序需要通过蓝牙搜索和连接设备,请确认手机蓝牙功能是否已开启?',showCancel: false,confirmText: '我已开启',success: async () => {const {bluetoothEnabled,platform} = uni.getSystemInfoSync();if (bluetoothEnabled) {// 开启蓝牙功能resolve(true);} else {toast({title: '手机蓝牙未开启'});}},});} else {// 开启蓝牙功能resolve(true);}});}
},

额外关闭提示:

<button class="search-btn" type="default" @click="toggleLocationTracking">{{ isTrackingLocation ? '关闭位置追踪' : '开启位置追踪' }}</button>// data
isTrackingLocation:false// methods
toggleLocationTracking() {if (this.isTrackingLocation) {this.stopLocationTracking();} else {this.startLocationTracking();}},
startLocationTracking() {uni.authorize({scope: 'scope.userLocation',success: () => {this.isTrackingLocation = true;uni.showToast({title: '已开启位置服务',icon: 'success'});},fail: () => {uni.showModal({title: '提示',content: '需要位置权限才能搜索蓝牙设备',confirmText: '去设置',success: (res) => {if (res.confirm) uni.openSetting();}});}});},
stopLocationTracking() {uni.getSetting({success: (res) => {if (res.authSetting['scope.userLocation']) {uni.showModal({title: '确认',content: '确定要关闭位置服务吗?关闭后将无法搜索新设备',success: (res) => {if (res.confirm) {// 实际微信小程序无法直接关闭权限,引导用户去设置页uni.openSetting({success: () => {this.isTrackingLocation = false;}});}}});}}});},
http://www.dtcms.com/wzjs/490613.html

相关文章:

  • 广州做网站的价格台州seo公司
  • 哪些在线网站可以做系统进化树重庆网页优化seo公司
  • 做房产网站能赚钱吗爱站关键词挖掘old
  • 淘宝客可以做返利网站吗株洲网站建设
  • 外贸网站赚钱怎么建立自己的网站平台
  • 做亚马逊产品测评的网站2022拉人头最暴利的app
  • 白云定制型网站建设在百度上怎么打广告
  • wordpress链接形式网站内部链接优化方法
  • 网站 日历插件网站推广计划书范文500字
  • 网站建设实施方案seo网站优化培训厂家报价
  • 网站集群建设价格推广品牌的方法
  • 校内 实训网站 建设结构优化设计
  • b2c网站资料怎么做微信怎么推广引流客户
  • 俄罗斯网站建设百度竞价广告投放
  • 服务器怎么建网站今日新闻最新消息50字
  • 中央气象台卫星云图网络建站优化科技
  • 天河网站建设哪个好百度云网盘官网
  • 张家港网站建设做网站黄页引流推广网站入口
  • 香港网站建设 深圳分公司sem是什么岗位
  • 基于h5的个人网站建设百度收录排名查询
  • 网页设计网站简单静态模板天津seo结算
  • 百度网盟如何选择网站外贸接单平台网站
  • 建立网站的步骤和费用品牌营销推广
  • 哈尔滨龙彩做网站多少钱seo优化的内容有哪些
  • 无锡梅村网站建设成长电影在线观看免费
  • 网站关键词选取方法品牌宣传活动策划方案
  • 潮汕疫情最新消息东莞网站优化公司哪家好
  • [网络收集]form表单及网站开发中常用js表单取值方法市场调研一般怎么做
  • 有域名有服务器如何做网站今日军事头条
  • 长沙市规划建设局网站软文外链代发