Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of BluetoothSocket for iOS?

I would like to transfer files between my bluetooth device and iphone. Is there something similar to android.bluetooth.BluetoothSocket on the iOS platform?

Some code samples on connecting to the bluetooth socket will be greatly appreciated.

like image 531
happymeal Avatar asked Oct 21 '22 06:10

happymeal


2 Answers

This article describes 5 ways to set up data exchange over Bluetooth; 2 of them (usage of private API and usage of Ringwald's BTStack on jailbroken devices) won't allow your app to be published on AppStore; one doesn't look to be a real option (MFi licensing). There are 2 options that could be useful:

  1. Using GameKit. This enables your app to have Bluetooth connectivity only with iOS devices. So seems it's not an option for you.

    Tutorial: http://code.tutsplus.com/tutorials/bluetooth-connectivity-with-gamekit--mobile-11610

  2. Using CoreBluetooth. Doesn't limit connectivity to iOS devices only but requires support for Bluetooth Low Energy (BLE) protocol from devices you're going to connect to. I investigated possibility to connect iOS and Android via BLE about year ago and came to conclusion that android devices didn't provide enough BLE support at that time. Maybe something has changed during past year. Please note that BLE doesn't provide a 'socket-like' paradigm, so it may not fit your needs.

    Tutorial: http://code.tutsplus.com/tutorials/ios-7-sdk-core-bluetooth-practical-lesson--mobile-20741

like image 163
Nikolay Mamaev Avatar answered Oct 28 '22 21:10

Nikolay Mamaev


For future visitors, you can open L2CAP channel from your CBPeripheral to have an unrestricted connection to transfer your data. See below for documentation and how to use example source code.

https://developer.apple.com/documentation/corebluetooth/cbperipheral/2880151-openl2capchannel

https://github.com/paulw11/L2CapDemo

Watch this from WWDC2017

like image 29
Prasad De Zoysa Avatar answered Oct 28 '22 20:10

Prasad De Zoysa