OBEXFileTransferServices not connecting

I am trying to write a macOS application that will connect to an already paired bluetooth phone and retrieve a list of address book entries and call records. This information should be available through the standard OBEX interface. I am relatively new to macOS development (although I have enough experience developing iOS) and I get the feeling that I'm doing something wrong at a very basic level.

Here are the snippets of my code:

First, I find a specific paired Bluetooth device at its address

let paired = IOBluetoothDevice.pairedDevices()
let device = paired?.first(where: { (device) -> Bool in
    return (device as? IOBluetoothDevice)?.addressString == "some_address"
}) as? IOBluetoothDevice

This really works fine, and I am returning a valid object. Then I collect the address book service and create a BluetoothOBEXSession for it.

let service = device!.getServiceRecord(for: IOBluetoothSDPUUID(uuid32:kBluetoothSDPUUID16ServiceClassPhonebookAccess.rawValue))
let obexSession = IOBluetoothOBEXSession(sdpServiceRecord: service!)

, . ( ) - OBEXFileTransfer - (, telecom/cch, :

let ftp = OBEXFileTransferServices(obexSession: obexSession!)
ftp!.delegate = self

if ftp!.connectToFTPService() == 0 {
     NSLog("\(ftp!.currentPath())") // -- empty
     ftp!.changeCurrentFolderForward(toPath: "telecom/cch")
     NSLog("\(ftp!.currentPath())") // -- empty
     ftp!.retrieveFolderListing()
}

( OBEX FTS, :

override func fileTransferServicesRetrieveFolderListingComplete(_ inServices: OBEXFileTransferServices!, error inError: OBEXError, listing inListing: [Any]!) {
    NSLog("Listing complete...")
}

override func fileTransferServicesConnectionComplete(_ inServices: OBEXFileTransferServices!, error inError: OBEXError) {
    NSLog("Connection complete...")

}

override func fileTransferServicesDisconnectionComplete(_ inServices: OBEXFileTransferServices!, error inError: OBEXError) {
    NSLog("Disconnect complete...")
}

override func fileTransferServicesAbortComplete(_ inServices: OBEXFileTransferServices!, error inError: OBEXError) {
    NSLog("Abort complete...")
}

?

Bluetooth macOS, - , , .

+4

Source: https://habr.com/ru/post/1679299/


All Articles