[英]Tizen Watch and iOS Connectivity Problems
My requirement is to create an application which transfer text from iOS device to Tizen Wearable.我的要求是创建一个将文本从 iOS 设备传输到 Tizen Wearable 的应用程序。 As per tizen documents I have used BLE for communication.
根据 tizen 文件,我使用 BLE 进行通信。 On our end architecture would be Tizen as central and iOS as peripheral where initial connection will be from tizen to iOS app.
在我们的最终架构中,Tizen 为中心,iOS 为外围,其中初始连接将从 tizen 到 iOS 应用程序。
For Tizen:对于泰森:
var remoteDevice = null;
var adapter = tizen.bluetooth.getLEAdapter();
function onDeviceFound(device) {
if (remoteDevice === null) {
remoteDevice = device;
console.log('Found device ' + device.name + '. Connecting...');
device.connect(connectSuccess, connectFail);
}
adapter.stopScan();
}
function connectFail(error) {
console.log('Failed to connect to device: ' + e.message);
}
function connectSuccess() {
console.log('Connected to device');
var serviceUUIDs = remoteDevice.uuids;
**var gattService = remoteDevice.getService(serviceUUIDs[0]); //error in this one**
var property = gattService.characteristics[0];
}
adapter.startScan(onDeviceFound);
For iOS BLE connection:对于 iOS BLE 连接:
private func setupPeripheral() {
let transferCharacteristic = CBMutableCharacteristic(type: TransferService.characteristicUUID, properties: [.notify, .writeWithoutResponse],value: nil,permissions: [.readable, .writeable])
let transferService = CBMutableService(type: TransferService.serviceUUID, primary: true)
transferService.characteristics = [transferCharacteristic]
peripheralManager.add(transferService)
self.transferCharacteristic = transferCharacteristic
}
peripheralManager.startAdvertising([CBAdvertisementDataServiceUUIDsKey: [TransferService.serviceUUID]])
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
switch peripheral.state {
case .poweredOn:
os_log("CBManager is powered on")
setupPeripheral()
case .poweredOff:
os_log("CBManager is not powered on")
return
case .resetting:
os_log("CBManager is resetting")
return
case .unauthorized:
os_log("Unexpected authorization")
return
case .unknown:
os_log("CBManager state is unknown")
return
case .unsupported:
os_log("Bluetooth is not supported on this device")
return
@unknown default:
os_log("A previously unknown peripheral manager state occurred")
return
}
}
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeTo characteristic: CBCharacteristic) {
os_log("Central subscribed to characteristic")
connectedCentral = central
}
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFrom characteristic: CBCharacteristic) {
os_log("Central unsubscribed from characteristic")
connectedCentral = nil
}
By implementing remoteDevice.getService(remoteDevice.uuids[0]) code I am getting error device not found exception.通过实施remoteDevice.getService(remoteDevice.uuids[0])代码,我收到错误设备未找到异常。
Same issue has been posted in this link also: https://developer.tizen.org/ko/forums/web-application-development/central-peripharal-client-server-architecture-ble-communication-tizen-wearable-ios-not-working?langredirect=1此链接中也发布了相同的问题: https : //developer.tizen.org/ko/forums/web-application-development/central-peripharal-client-server-architecture-ble-communication-tizen-wearable-ios-不工作?langredirect=1
If someone have faced similar kind of challenge and found required solution then please provide your valuable inputs as it is kind of blocker on our end.如果有人遇到过类似的挑战并找到了所需的解决方案,那么请提供您宝贵的意见,因为这对我们来说是一种阻碍。
Thanks In advance.提前致谢。
I am a Tizen developer and have never developed an iOS app.我是 Tizen 开发人员,从未开发过 iOS 应用程序。 I assume that the iOS app:
我假设 iOS 应用程序:
Please, ensure that your Tizen device finds the Apple BLE device, you want to connect, in the scan.请确保您的 Tizen 设备在扫描中找到您想要连接的 Apple BLE 设备。 Your Tizen app connects to the first BLE device it finds.
您的 Tizen 应用程序连接到它找到的第一个 BLE 设备。 It is OK as long as the Apple device is the only visible BLE device.
只要 Apple 设备是唯一可见的 BLE 设备就可以。 To be sure, that the Tizen client connects to the proper device, you need to filter out other devices in your
onDeviceFound
.为确保 Tizen 客户端连接到正确的设备,您需要过滤掉
onDeviceFound
其他设备。 For example, connect to the device with a particular Bluetooth name:例如,连接到具有特定蓝牙名称的设备:
function onDeviceFound(device) {
if (device.name=== [iOS BLE device name]) {
remoteDevice = device;
console.log('Found device ' + device.name + '. Connecting...');
device.connect(connectSuccess, connectFail);
}
adapter.stopScan();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.