当前位置:   article > 正文

uniapp开发安卓跟ios所遇问题集合_uniapp的ios和安卓兼容问题

uniapp的ios和安卓兼容问题

Android平台配置CPU类型

一般勾选armeabi-v7a跟arm64-v8a就好了

  • armeabi-v7a 第7代及以上的ARM处理器(ARM32位),市面上大多数手机使用此CPU类型。
  • arm64-v8a 第8代、64位ARM处理器(ARM64位),最近两年新发的设备使用此CPU类型,可以兼容使用armeabi-v7a的so库。
  • x86 少部分平板使用x86,AS模拟器中选了intel x86时使用x86处理器,以及其它常用三方模拟器通常使用x86

您的应用目前的目标 API 级别为 29,但其目标 API 级别必须最低为 30,这样才能确保应用基于最新 API 而构建

应用配置文件,加 targetSdkVersion:"30"

文档地址:uni-app官网

文档地址:uni-app官网

IOS隐私信息访问的许可描述

Appstore审核要求App在调用如下涉及隐私的API时必须说明调用原因

IOS自定义开屏启动界面

官网示例:uni-app官网

直接使用uniapp模板文件(点击下载)中提供的相对常用的 storyboard 模板,可在这个文件的基础上进行自定义图片,已经一些文本内容

应用版本名称跟应用版本号

在ios跟谷歌中上架,版本号需要不停的加一,不然无法上传到市场中

app国际化默认语言设置

一定要在这里设置

  1. let i18nConfig = {
  2. locale: uni.getLocale(),
  3. messages
  4. }

pages.json中设置 tabBar list中的国际化

  1. "tabBar": {
  2. "height": "50rpx",
  3. // 配置选中颜色
  4. "selectedColor": "#42dfbf",
  5. "color": "#b0b3bf", // 设置为与背景颜色相同
  6. "backgroundColor": "white", // 设置为透明
  7. // list 每一项
  8. "list": [{
  9. "iconPath": "./static/img/tabbar/new.png",
  10. "selectedIconPath": "./static/img/tabbar/new_sel.png",
  11. "pagePath": "pages/message/message",
  12. "text": "%nav.1%"
  13. }
  14. ]
  15. }

安卓跟ios下拉刷新效果

 pages.json

  1. {
  2. "pages": [
  3. {
  4. "path": "pages/index/index",
  5. "style": {
  6. "navigationBarTitleText": "下拉刷新",
  7. "enablePullDownRefresh": true
  8. }
  9. }
  10. ]
  11. }

index.vue

  1. export default {
  2. data() {
  3. return {
  4. text: '下拉刷新'
  5. }
  6. },
  7. onLoad: function (options) {
  8. //开始下拉刷新,调用后触发下拉刷新动画,效果与用户手动下拉刷新一致
  9. uni.startPullDownRefresh();
  10. },
  11. onPullDownRefresh() {
  12. //一秒后停止刷新动画
  13. setTimeout(function () {
  14. uni.stopPullDownRefresh();
  15. }, 1000);
  16. }
  17. }

iOS 取消底部的空白区域

  1. "safearea" : {
  2. //安全区域配置,仅iOS平台生效
  3. "bottom" : {
  4. // 底部安全区域配置
  5. "offset" : "none" // 底部安全区域偏移,"none"表示不空出安全区域,"auto"自动计算空出安全区域,默认值为"none"
  6. }
  7. }

app蓝牙开锁

官网相关文档:uni-app官网

先初始化蓝牙,然后开始搜寻蓝牙,开始搜寻后设置一个延时,超过一定时间取消搜寻 然后提示连接失败。如果找到了对应的设备,获取到设备信息,也关闭蓝牙搜寻。然后正式连接设备,连接成功设置uni.setBLEMTU 蓝牙最大传输单元,避免命令行太长无法传输到设备中。

最后获取蓝牙设备所有服务,然后获取蓝牙设备某个服务中所有特征值,然后就可以写入命令了,一般是要将字符串转为二进制数据,也就是字节数据,我在这个踩了很久,附上我转换成功的代码

  1. function hexStringToArrayBuffer(str) {
  2. if (!str) {
  3. return new ArrayBuffer(0);
  4. }
  5. var buffer = new ArrayBuffer(str.length);
  6. let dataView = new DataView(buffer)
  7. for (let i = 0; i < str.length; i++) {
  8. // console.log('str.charAt(i).charCodeAt()', str.charAt(i).charCodeAt())
  9. dataView.setUint8(i, str.charAt(i).charCodeAt()) // 必须是Unicode 编码
  10. }
  11. return buffer;
  12. }
  13. const inputString = `(${state.DeviceID},x,xxx,xxxx,xxxxx)`;
  14. const bytes = hexStringToArrayBuffer(inputString);

完整代码: 

  1. uni.openBluetoothAdapter({ //首先初始化蓝牙
  2. success(res) {
  3. console.log('1')
  4. uni.startBluetoothDevicesDiscovery({ //这里是开启蓝牙搜寻
  5. success: (res) => {
  6. console.log('2')
  7. setTimeout(() => {
  8. unlockingTimeout.push(setInterval(()=>{
  9. exceptionPrompt('未搜尋到藍牙鎖,可嘗試重新打開藍牙')
  10. claerUnlockingTimeout()
  11. uni.stopBluetoothDevicesDiscovery({ //当找到匹配的蓝牙后就关掉蓝牙搜寻
  12. success(res) {
  13. }
  14. })
  15. }, 25000))
  16. state.progressSta = true
  17. drawCircle(item, index)
  18. }, 100)
  19. uni.onBluetoothDeviceFound((res) => { //这一步是监听返回的蓝牙设备
  20. uni.getBluetoothDevices({
  21. success: res => {
  22. console.log('2.5',res.devices)
  23. res.devices.forEach(device => { //这一步就是去筛选找到的蓝牙中
  24. if (device.name == item.imei) {
  25. uni.stopBluetoothDevicesDiscovery({ //当找到匹配的蓝牙后就关掉蓝牙搜寻
  26. success(res) {
  27. }
  28. })
  29. console.log('3',device.deviceId)
  30. state.DeviceID = device.deviceId
  31. state.deviceName = item.imei
  32. uni.createBLEConnection({ //连接低功耗蓝牙设备
  33. deviceId: state.DeviceID, //传入刚刚获取的uuid
  34. success(res) {
  35. console.log('4',state.DeviceID)
  36. setTimeout(function() {
  37. uni.setBLEMTU({
  38. deviceId: state.DeviceID,
  39. mtu: 300,
  40. success(res) {
  41. console.log('设置成功', res)
  42. },
  43. fail(err) {
  44. console.log('设置失败', err)
  45. }
  46. })
  47. }, 300)
  48. setTimeout(function() {
  49. uni.getBLEDeviceServices({ //获取蓝牙设备所有服务
  50. deviceId: state.DeviceID,
  51. success(res) {
  52. console.log('5',res)
  53. if (uni.getSystemInfoSync().platform == "ios") {
  54. state.servicesList = res.services[0].uuid
  55. }else{
  56. state.servicesList = res.services[2].uuid
  57. }
  58. uni.getBLEDeviceCharacteristics({ //获取蓝牙设备某个服务中所有特征值
  59. deviceId: state.DeviceID,
  60. serviceId: state.servicesList,
  61. success(res) {
  62. console.log('6')
  63. state.characteristicList = res.characteristics
  64. uni.notifyBLECharacteristicValueChange({
  65. state: true,
  66. deviceId: state.DeviceID,
  67. serviceId: state.servicesList,
  68. characteristicId: state.characteristicList[2].uuid,
  69. success(res) {
  70. console.log('连接成功', res)
  71. uni.onBLECharacteristicValueChange((res) => {
  72. console.log(`characteristic ${JSON.stringify(res)} has changed`)
  73. let hhh = ab2hex(res.value)
  74. console.log("监听成功", hexCharCodeToStr(hhh))
  75. })
  76. setTimeout(() => {
  77. sendInstruction(item)
  78. }, 500)
  79. },
  80. fail(res) {
  81. exceptionPrompt()
  82. console.log(JSON.stringify(res))
  83. }
  84. })
  85. },
  86. fail(res) {
  87. if (uni.getSystemInfoSync().platform == "ios") {
  88. if(res.code == '10012'){
  89. state.defeated = false
  90. state.progressSta = false
  91. state.progress = 0
  92. state.lockhead = true
  93. state.textSta = instance.proxy.$t('bluetooth.8')
  94. messagePopup.value.showMessage('warn', '未找到設備,請重試')
  95. }
  96. }
  97. console.log(JSON.stringify(res))
  98. }
  99. })
  100. },
  101. fail(res) {
  102. exceptionPrompt()
  103. console.log(JSON.stringify(res))
  104. }
  105. })
  106. }, 1500)
  107. },
  108. fail(res) {
  109. if(res.code == '10012'){
  110. state.defeated = false
  111. state.progressSta = false
  112. state.progress = 0
  113. state.lockhead = true
  114. state.textSta = instance.proxy.$t('bluetooth.8')
  115. messagePopup.value.showMessage('warn', '連接超時,請重試')
  116. }
  117. console.log(res)
  118. }
  119. })
  120. }
  121. })
  122. },
  123. fail: e => {
  124. console.log(e)
  125. }
  126. });
  127. })
  128. }
  129. })
  130. },
  131. fail(res) {
  132. if (res.code == 10001) {
  133. messagePopup.value.showMessage('warn', "藍牙是否打開")
  134. } else {
  135. messagePopup.value.showMessage('warn', res.errMsg)
  136. }
  137. }
  138. })

其他蓝牙开锁文章:uni-app蓝牙开锁篇 - DCloud问答

uni-app使用蓝牙 - 伟衙内 - 博客园 (cnblogs.com)

app中绘制图表

uChar插件文档地址:uCharts官网 - 秋云uCharts跨平台图表库

app实现国际化功能

使用uni-hello-i18n,官方有示例

示例地址:hello-i18n 示例工程 - DCloud 插件市场

官方文档:uni-app官网 

补充,国际化的繁体、简体跟英文一定要设置为 zh-Hant、zh-Hans、en 因为uniapp的内置插件会根据这个也进行国际化的切换

  1. import en from './en.json'
  2. import zhHans from './zh-Hans.json'
  3. import zhHant from './zh-Hant.json'
  4. export default {
  5. en,
  6. 'zh-Hans': zhHans,
  7. 'zh-Hant': zhHant
  8. }

app二维码

插件地址:uQRCode 全端二维码生成插件 支持nvue 支持nodejs服务端 - DCloud 插件市场

  1. <uqrcode ref="uqrcode" canvas-id="qrcode" :value="qrcodeData" :options="{ margin: 10 }"></uqrcode>
  2. <script>
  3. import {
  4. reactive,
  5. ref,
  6. toRefs,
  7. getCurrentInstance,
  8. onMounted
  9. } from 'vue';
  10. export default {
  11. setup() {
  12. let qrcodeData = ref('')
  13. let uqrcode = ref(null)
  14. function saveQRCode() {
  15. uqrcode.value.save({
  16. success: () => {
  17. messagePopup.value.showMessage('success', instance.proxy.$t('otherMy.9'))
  18. }
  19. })
  20. }
  21. return {
  22. ...toRefs(state),
  23. qrcodeData,
  24. saveQRCode,
  25. uqrcode
  26. };
  27. }
  28. };
  29. </script>

 未完待续... ...

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/841094
推荐阅读
相关标签
  

闽ICP备14008679号