A very simple library to discover and retrieve data from nearby devices (even if the peer app works at background).

Related tags

Bluetooth Discovery
Overview

Discovery: A simple library to discover and retrieve data from nearby devices.

Screenshot

Discovery is a very simple but useful library for discovering nearby devices with BLE(Bluetooth Low Energy) and for exchanging a value (kind of ID or username determined by you on the running app on peer device) regardless of whether the app on peer device works at foreground or background state.

Version

###Discovery:###

  • lets you easily discover nearby devices
  • retrieve their id(assigned by you) while the app works on either foreground or background state
  • hides the nitty gritty details of BLE calls and delegates from the developer
  • determines the proximity of the peer device

###Version 1.1:###

  • You can initialize Discovery either in only Detection or only Broadcasting mode. The default initializer will start the both.

Example App

I added a simple but cool example alongside with the library. Simply download, run pod install and install it on two or more of your bluetooth enabled devices and have some fun. It works both on iPhone and iPad.

Install

pod 'Discovery', '~> 1.0'

Example usage

// create our UUID.
NSString *uuidStr = @"B9407F30-F5F8-466E-AFF9-25556B57FE99";
CBUUID *uuid = [CBUUID UUIDWithString:uuidStr];
    
__weak typeof(self) weakSelf = self;
    
// start Discovery
self.discovery = [[Discovery alloc] initWithUUID:uuid username:self.username usersBlock:^(NSArray *users, BOOL usersChanged) {
        
    NSLog(@"Updating table view with users count : %d", users.count);
    weakSelf.users = users;
    [weakSelf.tableView reloadData];
}];

The Concept, The Problem, and why we need Discovery?

Let's make clear what we are trying to solve: Our aim is to handle the problem of discovering other devices (that are our running our app too), and exchanging an ID (could be username, name or a numbered id) even if our app on the peer device runs at background.

If you have dived into the concepts of BLE and iBeacon you probably know that iOS has some limitations on how you can harness these features. iBeacons are basically subset of BLE technology. You can program your device to be both an advertiser and a listener. However it is not possible to advertise as iBeacon when your app runs at background state. Moreover, you can only transmit major and minor values which are also limiting.

Thus, directly using BLE functions are more convenient. Yet, we have some problems there too! Basically, the problem here lies again on the state of your app, namely, exchanging usernames(or any kind of ID) at both foreground and background states. If your app runs on foreground state, there isn't any problem. We can simply attach data which is our username, and when the peer device detects our signal, it will retrieve the username via CBAdvertisementDataLocalNameKey. However, iOS trims that information when our app goes into background state. It still continues to advertise, but the data(username) your are trying transmit can not be read by other peers. So we need some other methods to determine who that device belongs to.

Discovery solves this problem by creating some specific characteristics that is binded to the service of the advertiser. When the listener peer discovers our device, it initially checks whether it can read the CBAdvertisementDataLocalNameKey value. If it can, there is no problem, the device is identified. If it can't read (which means our app is at background state) it attempts to connect and discover our services. After the connection is successful, the peer device goes through our services and it reads our characteristics, and there it retrieves our username - voilà! Then, simply disconnects.

What's next?

I wanted to keep Discovery as simple as possible for the initial release. In the next release I will probably add some reliable error handling and some callbacks for the developer to interfere whenever necessary. And maybe some time later, I could add some extra features for peers to persistently connect each other and continue exchanging stream of information.

Problematic Cases

Have a look at this question on Stackoverflow. In my experience, I did't encounter this problem on iOS8, only sometimes on iOS7.

Contribution

Please don't hesitate to send pull requests, however I only accept it on develop branch.

Contact

Ömer Faruk Gül

My LinkedIn Account

Comments
  • It does not show other people nearby

    It does not show other people nearby

    Hello, i've compiled and installed the app in two iphone 5 with 8.1 installed , but when i run it and put the username in form, but don't show the people nearby. How it's possibile ? it dosen't work anymore?

    Another question, theoretically it is possible ti implement this in android ? or the bluetooth signal search only ios device?

    Thanks

    Alex

    opened by realexhub 2
  • scan in background

    scan in background

    Hi, great work! Short question: Is it even possible to scan for a device in background. Or in other words: Is it possible to exchange data("String") between two devices which are both in locked background mode.

    Best!

    opened by darwin2k 2
  • multiple instances of discovery

    multiple instances of discovery

    Hey @omergul123 , Great library! I've been grappling with iBeacon (and trying to simulate it using CB) so looking forward to trying this out. Quick question: Do you see any issue with using multiple instances of discovery within the same app? i.e. one instance to discover nearby devices and multiple other instances advertising?

    opened by yonahforst 2
  • Start options

    Start options

    currently discovery objects are started both discovering and advertising. This pull request adds a new initializer with the following options: DIStartAdvertisingAndDetecting, DIStartAdvertisingOnly, DIStartDetectingOnly, DIStartNone

    The default functionality still works as it did. The default initializer calls this new one with DIStartAdvertisingAndDetecting.

    opened by yonahforst 1
  • Start options

    Start options

    currently discovery objects are started both discovering and advertising. This pull request adds a new initializer with the following options: DIStartAdvertisingAndDetecting, DIStartAdvertisingOnly, DIStartDetectingOnly, DIStartNone

    The default functionality still works as it did. The default initializer calls this new one with DIStartAdvertisingAndDetecting.

    opened by yonahforst 1
  • I need to hire you for a small project.

    I need to hire you for a small project.

    Hi Omer,

    I am looking for a developer like you, who's expert in BLE. I need some help understanding the concept of this. I would be ready to pay you for the same. So please message me back if you're interested. In my believe, this would not take more than 2 hours.

    opened by hemangshah 0
  • pod installs wrong directory

    pod installs wrong directory

    I think the root 'Discovery' directory and the 'DiscoveryExample/Discovery' example are mixed up. The latter contains all the useful code but the pod installs from the first one.

    opened by yonahforst 0
  • Easy Install...

    Easy Install...

    Hello, Is it possible to make it to be able install the old fashion way with drag & drop and NOT with pod If you do so, please include all necessary classes.....

    George Gerardis

    opened by geogerar 0
  • Strange behaviour on iOS 11

    Strange behaviour on iOS 11

    Hello,

    I have 3 devices: 2 are running iOS 11, and 1 is running iOS 8. I start advertising on all 3 devices, and they can see each other. However, when I put one iOS 11 device to sleep, the other iOS 11 device cannot discover it anymore. The iOS 8 device still can discover the sleep one with no problems.

    Do you have any experiences running Discovery on iOS 11?

    Did you run into any similar problems? How did you solve it?

    Thanks!

    opened by longmaba 0
  • messaging?

    messaging?

    thanks for the library!

    i see in the readme that you plan to eventually add features like communications between devices. Is this planned for the near future?

    opened by mvayngrib 0
  • Start advertise and discovery services on init

    Start advertise and discovery services on init

    Currently _shouldAdvertise and _shouldDiscover are being set directly, bypassing [setShouldAdvertise] and [setShouldDiscover]. This pull request calls the functions directly, making sure that the CBPeripheralManager and CBCentralManager are initialized in order for the services to start based off the startOption defined by the user.

    opened by connorgiles 0
  • Not getting any nearby device

    Not getting any nearby device

    Hello Omer

    I am trying to run your code in 3 devices with different uuid and username but none of device showing near by device. what could lead to problem?

    Thanks

    opened by jrajodi 1
Owner
Ömer Faruk Gül
Ömer Faruk Gül
Nearby earthquake tracking app

Earthquake Tracker Description An application for tracking earthquakes in a radius of 2500 km from the user's location in the last month. Information

Anastasia Bespalova 0 Dec 9, 2021
Diabetes: test the FreeStyle Libre glucose sensor as a Bluetooth Low Energy device, even directly from an Apple Watch.

Since the FreeStyle Libre 2 / 3 glucose sensors are Bluetooth Low Energy devices, I am trying to leverage their capabilities to implement something ne

Guido Soranzio 6 Jan 2, 2023
The easiest way to use Bluetooth (BLE )in ios,even bady can use.

The easiest way to use Bluetooth (BLE )in ios,even bady can use.

刘彦玮 4.6k Dec 27, 2022
This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE.

BLE Serial IOs Example This is a simple app, which scans for BLE Peripherials and connect to them. The example works with NORDIC_UART_SERVICE. UUIDS H

Muhammad Hammad 4 May 10, 2022
📱📲 A wrapper for the MultipeerConnectivity framework for automatic offline data transmission between devices

A wrapper for Apple's MultipeerConnectivity framework for offline data transmission between Apple devices. This framework makes it easy to automatical

Wilson Ding 197 Nov 2, 2022
The official Swift Library for Vital API, HealthKit and Devices

vital-ios The official Swift Library for Vital API, HealthKit and Devices Install We currently support SPM. Documentation Please refer to the official

Vital 17 Dec 22, 2022
A simple framework that brings Apple devices together - like a family

Apple Family A simple framework that brings Apple devices together - like a family. It will automatically use bluetooth, wifi, or USB to connect and c

Kiran 62 Aug 21, 2022
RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant.

RxBluetoothKit is a Bluetooth library that makes interaction with BLE devices much more pleasant. It's backed by RxSwift and CoreBluetooth and it prov

Polidea 1.3k Jan 6, 2023
Fluetooth - Flutter library for sending bytes to Bluetooth devices on Android/iOS

A Flutter library for sending bytes to Bluetooth devices. Available on Android a

Iandi Santulus 1 Jan 2, 2022
BluetoothKit Easily communicate between iOS devices using BLE.

BluetoothKit Easily communicate between iOS devices using BLE. Background Apple mostly did a great job with the CoreBluetooth API, but because it enca

Rasmus Høhndorf Hummelmose 2.1k Jan 8, 2023
Build your own 'AirTags' 🏷 today! Framework for tracking personal Bluetooth devices via Apple's massive Find My network.

OpenHaystack is a framework for tracking personal Bluetooth devices via Apple's massive Find My network.

Secure Mobile Networking Lab 5.8k Jan 9, 2023
Simple, block-based, lightweight library over CoreBluetooth. Will clean up your Core Bluetooth related code.

LGBluetooth Simple, block-based, lightweight library over CoreBluetooth. Steps to start using Drag and Drop it into your project Import "LGBluetooth.h

null 170 Sep 19, 2022
CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework

CombineCoreBluetooth is a library that bridges Apple's CoreBluetooth framework and Apple's Combine framework, making it possible to subscribe to perform bluetooth operations while subscribing to a publisher of the results of those operations, instead of relying on implementing delegates and manually filtering for the results you need.

Starry 74 Dec 29, 2022
The Bluetooth LE library for iOS and Mac. 100% Swift.

iOS-BLE-Library An in-development Bluetooth Low Energy Library by Nordic Semiconductor to interact with the , which is not complicated, but requires w

Nordic Semiconductor 6 Dec 19, 2022
Bluejay is a simple Swift framework for building reliable Bluetooth LE apps.

Bluejay is a simple Swift framework for building reliable Bluetooth LE apps. Bluejay's primary goals are: Simplify talking to a single Bluetooth LE pe

Steamclock Software 1k Dec 13, 2022
BLE (Bluetooth LE) for U🎁 Bleu is the best in the Bluetooth library.

Bleu Bleu is a Bluetooth library. Bleu is the easiest way to operate CoreBluetooth. Bleu is possible to operate by replacing Bluetooth 's Peripheral a

1amageek 484 Dec 29, 2022
A small library that adds concurrency to CoreBluetooth APIs.

AsyncBluetooth A small library that adds concurrency to CoreBluetooth APIs. Features Async/Await APIs Queueing of commands Data conversion to common t

Manuel Fernandez 83 Dec 28, 2022
MacOS app which allows drag and drop of images to BLE thermal printers

Print2BLE Copyright (c) 2021 BitBank Software, Inc. Written by Larry Bank [email protected] What is it? This project is a MacOS GUI applicatio

Larry Bank 37 Jan 5, 2023
An app for questioning people to try on different names and pronouns. A winner of the Swift Student Challenge 2022.

DiscoverMe is an app for questioning, trans, nonbinary, and gender-nonconforming people to try on different names and pronouns that better suit their

Joshua Tint 6 Oct 2, 2022