-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
macOS Support #6
Comments
Working on it 👍 |
Awesome! I'm here if you have any questions about the code. |
progress update - got the application compiling to .app with the demo ui, so I still need to make the ui implementation. The bluetooth connection seems a bit more challenging, see https://stackoverflow.com/a/59413196/9729726, looks like I can't easily send data using sockets. Any ideas? |
My friend @Mr-M33533K5 worked on this for a bit, and IIRC he reached the conclusion that it's possible. See: https://developer.apple.com/documentation/iobluetooth/iobluetoothrfcommchannel |
progress update - I got the gui working I guess, can't really test it because it crashes on the bluetoothconnector, so the only thing to do is to make the bluetooth connector |
@semvis123 When I click "connect", the following error message occurred: (It failed when calling
I am not entirely sure what happened, but in your code you set delegate to nil when opening a RFCOMM channel, but according to the document https://developer.apple.com/documentation/iobluetooth/iobluetoothdevice/1431606-openrfcommchannelsync?language=objc :
It doesn't seem like using nil as delegate should really work. // create new channel
IOBluetoothRFCOMMChannel *channel = [[IOBluetoothRFCOMMChannel alloc] init];
if ([device openRFCOMMChannelSync: &channel withChannelID:1 delegate: nil] == kIOReturnSuccess) {
const int connectResult = kIOReturnSuccess;
printf("%d", connectResult);
this->_connected = true;
} |
Hmmm, it should work though, I saw it in an old file, where it uses nil as delegate: source. I guess it's because the channel id is probably incorrect. But I don't know for sure. Note: saw most people use |
@semvis123 Here's the code of IOService: https://fergofrog.com/code/cbowser/xnu/iokit/IOKit/IOService.h.html
So it seems like our app cannot talk to the kernel and bluetooth driver properly at all. (notice the original error message is during I've saw some apps that use these api and I've seem some complain about their app not working (same error I would guess that apple changed the kernel in a way that breaks these super old apis? (bluetooth related functionalities is added to OSX back in 2002). Or apple just dropped the support deliberately. I don't know for sure. Considering that Sony Headphones Connect has an iOS app, which surely uses RFCOMM as well, I'm sure that the kernel still supports it though. I might give Swift a try and see if things are different. |
@Miigon From what I read, RFCOMM is available on iOS only for companies that got approval from Apple (otherwise you only have GATT), and that it's available for everyone on macOS. Docs linked above seem to imply that this is the case. I know very little about macOS though, so take that with a grain of salt. |
Found this on Github, but when it connects to the wh-1000-xm3 it gives an error which indicates that the device isn't an SPP/RFCOMM device. Is this correct or is this something Sierra(and up) related? |
Well, it expects the rfcomm device to be the first device that you Mac have connected to. But in my case my 1000xm3 is the second device(I know it from Xcode debugger). I changed the code so that it will try to connect to my 1000xm3, instead of connecting to my mouse, which is the first device. // line 75, MacosBT.mm
IOBluetoothDevice *device = [deviceArray objectAtIndex:1]; // objectAtIndex:0 -> objectAtIndex:1 Another thing I changed is this line: // line 78, MacosBT.mm and line 96, MacosBT.mm
IOBluetoothSDPUUID *sppServiceUUID = [IOBluetoothSDPUUID uuid16: kBluetoothSDPUUID16RFCOMM];
// uuid16: kBluetoothSDPUUID16ServiceClassSerialPort -> uuid16: kBluetoothSDPUUID16RFCOMM The original code is looking for a After these changes, the program can run past the two "not SPP/RFCOMM device" checks and can actually get And guess what?
No NULLing, no nothing. it just connects! I suspect that the channelID is the cause of problem, so I put Sure enough, it connects. So a channelID of 0x10 works, but I think it would still be a good idea to use |
Wow that's some good information! The next step is to make the opened channel globally accessible, so it can be accessed in the other functions (like disconnect). Note: the headphones can currently only connect once because it probably doesn't disconnect (if you turn the headphones off and back on it will work again). |
Got some work done! The connection works and disconnect works kinda, when the channel is closed it cannot be opened again (currently solved by disconnecting from the device). Send data and receive data are now also correctly structured, send command doesn't work though ( do I need to use the byte magic file? or is this maybe cause the function doesn't return anything? or another possibility, is this because of the receive function not working?), receive always prints null (string conversion error maybe?). pull request and fork have been updated
|
@semvis123, The recv function has to work since the protocol has some synchronization built in, and that requires our side to receive some data. I'll take a look at everything on Monday. |
how's everything going buddies? |
@Miigon Some progress has been made! Check my pull request for the most up to date information. |
@Miigon Could you test the new version please? |
@Plutoberth Sure, I've done testing it. It isn't quite working yet. I've detailed everything in the pull request comment. |
@Miigon thanks! |
Forgot to close this :) |
Please react to this issue if you want macOS support
The text was updated successfully, but these errors were encountered: