Go to file
Zsombor Szabo ba8923b21b Add maxNumberOfConcurrentPeripheralConnections tweak for tvOS 2020-01-26 08:37:36 +02:00
Sources Add maxNumberOfConcurrentPeripheralConnections tweak for tvOS 2020-01-26 08:37:36 +02:00
Tests Add support for watchOS and tvOS platforms. 2020-01-22 15:10:56 +02:00
.gitignore First commit 2019-09-30 10:13:38 +03:00
LICENSE.txt First commit 2019-09-30 10:13:38 +03:00
Package.swift Fix runtime crash related to bitcode recompilation and KVO on watchOS 2020-01-25 14:31:22 +02:00
README.md Update README.md 2020-01-22 18:39:59 +02:00

README.md

Berkanan SDK

Berkanan SDK enables Bluetooth-powered mesh messaging between nearby apps. It's the framework used by Berkanan (Product Hunt, TechCrunch) and Berkanan Lite (GitHub).

With Berkanan SDK apps can discover nearby apps, which also have the SDK integrated, and send them small messages via Bluetooth. The range for messages is about 70 meters, but they can reach further because the SDK automatically resends them upon receiving. The more apps use Berkanan SDK, the bigger the network and further the reach of the messages gets.

Features and Limitations

  • Free and open-source: Contributions are welcome!
  • Bluetooth-powered: No need for Wi-Fi or cellular connectivity.
  • Background: On iOS it works even while the app is in the background.
  • Connectionless communication with no pairing, no sessions and no limit on the number of apps.
  • Messages are sent using flooding where duplicates are filtered by tracking their identifiers and decreasing their time to live (TTL) by 1 until they reach 0, as they travel from app to app.
  • The message range limit between two devices is about 70 meters.
  • The data size limit is 512 bytes.
  • No built-in support for encryption, acknowledgment or store and forward; you have to roll your own if your use case requires it.
  • Supported operating systems: iOS v9.0 or later, macOS v10.13 or later, watchOS v2.0 or later, tvOS v9.0 or later

Privacy Policy

Berkanan SDK does not send the messages to any central server or company — this can be verified by looking at its source code. If your app's messages contain sensitive information (e.g., a private text message) you should use encryption.

Integrating Berkanan SDK into Your App

iOS

To integrate Berkanan SDK into your iOS app, the easiest way is to use Xcode 11 or later. Open the .xcodeproj or .xcworkspace file of your app and follow these steps.

Configuring your app target

Select your app target and then go to Editor / Add Capability / Background Modes. Check both Uses Bluetooth LE accessories and Acts as a Bluetooth LE accessory.

Go to Signing & Capabilities / App Sandbox and check the Bluetooth checkbox.

Add NSBluetoothAlwaysUsageDescription and NSBluetoothPeripheralUsageDescription to the Info.plist with the value:

Allow access to the Berkanan Bluetooth Service to be able to communicate even while offline.

Adding Berkanan SDK to your app

Go to File / Swift Packages / Add Package Dependency... and enter https://github.com/zssz/BerkananSDK.git

Add @import BerkananSDK to your source files where needed.

Using Berkanan SDK in your app

Initializing a local service with a configuration to advertise
let configuration = Configuration(
  // The identifier is used to identify what kind of configuration the service has. 
  // It should be the same across app runs.
  identifier: UUID(uuidString: "3749ED8E-DBA0-4095-822B-1DC61762CCF3")!, 
  userInfo: "My User Info".data(using: .utf8)!
)
// Throws if the configuration is too big or invalid.
let service = try BerkananBluetoothService(configuration: configuration)
Starting a local service
service.start()
Discovering nearby services and their advertised configuration
let discoverServiceCanceller = service.discoverServiceSubject
  .receive(on: RunLoop.main)
  .sink { service in
    print("Discovered \(service) with \(service.getConfiguration())")
}
Constructing a message with a payload type identifier and payload
let message = Message(
  // The payloadType is used to identify what kind of payload the message carries.
  payloadType: UUID(uuidString: "E268F3C1-5ADB-4412-BE04-F4A04F9B3D1A")!,
  payload: "Hello, World!".data(using: .utf8)
)
Sending a message
// Throws if the message is too big or invalid.
try service.send(message)
Receiving messages
let receiveMessageCanceller = service.receiveMessageSubject
  .receive(on: RunLoop.main)
  .sink { message in
    print("Received \(message.payloadType) \(message.payload)")
}
Stopping the service
service.stop()

Sample app

To see how Berkanan SDK is integrated into Berkanan Lite, check out its source code.