Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
visualcloud
/
Vmatrix-client-taro
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
fc4540a6
authored
Aug 26, 2019
by
lirandong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
解决 iOS 获取蓝牙特征信息失败问题
parent
24fe9cbc
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
16 deletions
+50
-16
src/common/bluetooth.ts
+41
-12
src/common/token.ts
+5
-1
src/pages/home/user/index.tsx
+1
-1
src/pages/index.tsx
+3
-2
No files found.
src/common/bluetooth.ts
View file @
fc4540a6
...
...
@@ -63,11 +63,36 @@ class Bluetooth {
/** 连接蓝牙 */
async
createBLEConnection
(
deviceId
:
string
)
{
await
bluetooth
.
createBLEConnection
({
deviceId
})
bluetooth
.
stopBluetoothDevicesDiscovery
()
bluetooth
.
onBLEConnectionStateChange
(({
connected
})
=>
{
showMyToast
({
title
:
connected
?
'蓝牙已连接'
:
'蓝牙已断开'
})
})
try
{
await
bluetooth
.
createBLEConnection
({
deviceId
})
bluetooth
.
stopBluetoothDevicesDiscovery
()
await
this
.
getBLEDeviceServices
(
deviceId
)
}
catch
(
error
)
{
console
.
error
(
error
)
}
}
/** 获取蓝牙服务列表, 初始化蓝牙服务列表 */
async
getBLEDeviceServices
(
deviceId
:
string
)
{
Taro
.
showLoading
({
title
:
'获取蓝牙参数...'
})
const
{
services
}
=
await
bluetooth
.
getBLEDeviceServices
({
deviceId
})
// 获取服务列表
Taro
.
showLoading
({
title
:
'获取特征值...'
})
const
serveList
:
Array
<
Promise
<
Taro
.
getBLEDeviceCharacteristics
.
Promised
>>
=
[]
for
(
const
iterator
of
services
)
{
const
serve
=
bluetooth
.
getBLEDeviceCharacteristics
({
deviceId
,
serviceId
:
iterator
.
uuid
})
// 获取特征服务
serveList
.
push
(
serve
)
}
const
serveListRes
=
await
Promise
.
all
(
serveList
)
serveListRes
.
forEach
(({
characteristics
})
=>
{
console
.
log
({
characteristics
})
})
}
/** 打开蓝牙的监听功能 */
...
...
@@ -111,17 +136,21 @@ class Bluetooth {
/** 整理WiFi列表的信息包 */
async
formatWifiList
(
deviceId
:
string
,
value
:
ArrayBuffer
)
{
const
{
page
,
advertisData
}
=
await
analysisPage
(
value
)
if
(
page
===
0
)
{
// 数据传输完毕
this
.
getWifiListCallBack
&&
this
.
getWifiListCallBack
(
JSON
.
parse
(
advertisData
))
try
{
const
{
page
,
advertisData
}
=
await
analysisPage
(
value
)
if
(
page
===
0
)
{
// 数据传输完毕
this
.
getWifiListCallBack
&&
this
.
getWifiListCallBack
(
JSON
.
parse
(
advertisData
))
}
bluetooth
.
writeBLECharacteristicValue
({
deviceId
,
serviceId
:
BLE_SERVICE_ID
,
value
:
new
Uint8Array
([
page
]).
buffer
,
characteristicId
:
WIFI_CHARACTERISTIC_ID
})
}
catch
(
error
)
{
console
.
error
(
'获取WiFi列表'
,
error
)
}
bluetooth
.
writeBLECharacteristicValue
({
deviceId
,
serviceId
:
BLE_SERVICE_ID
,
value
:
new
Uint8Array
([
page
]).
buffer
,
characteristicId
:
WIFI_CHARACTERISTIC_ID
})
}
/** 整理WiFi连接状态信息 */
...
...
src/common/token.ts
View file @
fc4540a6
...
...
@@ -11,7 +11,11 @@ class Token {
init
()
{
if
(
!
this
.
initDone
)
{
this
.
initDone
=
true
return
this
.
getStorageToken
()
const
token
=
this
.
getStorageToken
()
if
(
!
token
)
{
Taro
.
navigateTo
({
url
:
'/pages/login/index'
})
}
return
token
}
}
...
...
src/pages/home/user/index.tsx
View file @
fc4540a6
...
...
@@ -58,7 +58,7 @@ class User extends Component {
logOut
()
{
token
.
reset
()
Taro
.
navigateTo
({
url
:
'/pages/login/index
.tsx
'
})
Taro
.
navigateTo
({
url
:
'/pages/login/index'
})
}
shouldComponentUpdate
(
_nextPorps
,
_nextState
)
{
...
...
src/pages/index.tsx
View file @
fc4540a6
...
...
@@ -21,12 +21,13 @@ interface Index {
}
class
Index
extends
Component
{
init
=
false
config
:
Config
=
{
navigationBarTitleText
:
''
,
navigationStyle
:
'custom'
}
constructor
(
props
)
{
super
(
props
)
componentWillMount
()
{
this
.
initToekn
()
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment