Reputation: 564
My requirement is to create an application which transfer text from iOS device to Tizen Wearable. As per tizen documents I have used BLE for communication. On our end architecture would be Tizen as central and iOS as peripheral where initial connection will be from tizen to iOS app.
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:
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.
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
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.
Upvotes: 0
Views: 353
Reputation: 1
I am a Tizen developer and have never developed an iOS app. I assume that the iOS app:
Please, ensure that your Tizen device finds the Apple BLE device, you want to connect, in the scan.
Your Tizen app connects to the first BLE device it finds. It is OK as long as the Apple device is the only visible BLE device.
To be sure, that the Tizen client connects to the proper device, you need to filter out other devices in your 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();
}
Upvotes: 0