• Stars
    star
    252
  • Rank 161,312 (Top 4 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created almost 11 years ago
  • Updated almost 11 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Objective-C Apple Notification Center Service Client

INDANCSClient

Objective-C Apple Notification Center Service Implementation

Overview

This is an Objective-C client and server implementation of the Apple Notification Center Service (ANCS) specification. This allows Bluetooth LE devices to connect to an iOS device running iOS 7 or later and receive all push/local notifications.

This project contains two main parts:

  1. INDANCSServer (iOS 7+) - a small component that runs on an iOS device to expose the ANCS service and some device information (name, model).
  2. INDANCSClient (OS X 10.9+) - a Mac framework that has a simple block based API for scanning and registering for notifications from iOS devices that are running the INDANCSServer code.

I made this because it was a great way to learn the ins and outs of Core Bluetooth and because the idea of wirelessly receiving notifications from an iOS device is way cool.

WARNING: This is alpha quality code and hasn't been tested in production. Also, unit tests are yet to be implemented.

Requirements

  • iPhone 4S/iPad 3 or better running iOS 7 or higher. Previous iPhone models (including iPhone 4) do not support Bluetooth 4.0.
  • A Mac with Bluetooth 4.0 support running OS X 10.9 or higher. Macs made after mid-2011 support Bluetooth 4.0 (starting with the mid-2011 MacBook Air). See this page for more info.

Getting Started

The easiest way to try out this project is to simply compile and run the INDANCSiPhone and INDANCSMac example projects on your iOS device and Mac, respectively.

If both devices have Bluetooth turned on, you should see a notification from the Mac app indicating that it has found your iOS device and from this point, any notification from the iOS device should appear in the Mac app's table view. Use the "Post Test Notification" button in the iOS app to try it instantly.

The sections below go into more detail on how to configure INDANCSServer and INDANCSClient in your own project.

INDANCSServer

While the ANCS service exists on all iOS 7+ devices, it requires additional code to expose the service to outside peripherals. With INDANCSServer, this only takes a couple lines of code.

Link against CoreBluetooth.framework and start advertising:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.server = [[INDANCSServer alloc] initWithUID:@"INDANCSServer"];
	[self.server startAdvertising];
    return YES;
}

The UID parameter allows you to specify a restoration identifier for use with iOS 7's Bluetooth State Preservation/Restoration features.

If you want to advertise the ANCS service while the app is in the background, you also need to add the bluetooth-peripheral background mode to your Info.plist file.

INDANCSClient

INANCSClient is distributed as a Mac framework.

Scanning

INDANCSClient provides a simple block-based API for scanning for iOS devices that are running INDANCSServer:

#import <INDANCSClient/INDANCSClientFramework.h>

self.client = [[INDANCSClient alloc] init];
[self.client scanForDevices:^(INDANCSClient *client, INDANCSDevice *device) {
	NSLog(@"Found device: %@", device.name);
}];

Registering for Notifications

At the point where a device is found by -scanForDevices:, INDANCSClient has already connected to the device (necessary in order to retrieve device information). It will remain connected for a period of time that can be set using the registrationTimeout property. It is best to register for notifications within this window so that INDANCSClient doesn't need to reconnect to the device.

Notification registration also uses a simple block-based API:

[client registerForNotificationsFromDevice:device withBlock:^(INDANCSClient *c, INDANCSNotification *n) {
	NSLog(@"Notification: %@ - %@", n.title, n.message);
}];

The INDANCSNotification object has all the information about the notification, including the device & application that it came from. Of particular importance is the latestEventID property, which tells you whether the notification was created, modified, or removed.

Connection State

The INDANCSClientDelegate protocol documented in INDANCSClient.h has methods that inform the delegate about the connection state (e.g. when a device disconnects or fails to connect).

Since Bluetooth connections can often be unreliable, INDANCSClient includes support for automatically attempting reconnection when a device disconnects through the attemptsAutomaticReconnection property, which is set to YES by default.

Caching

INDANCSClient implements an on-disk and in-memory cache of app attributes, as recommended by Apple's guidelines to avoid wasting energy by requesting app information over Bluetooth every time a notification is received.

The INDANCSKeyValueStore protocol describes the interface that you can use to implement your custom key-value store for use with INDANCSClient. Two existing implementations are provided with the framework:

  • INDANCSInMemoryStore - An in-memory key-value store backed by an NSDictionary.
  • INDANCSObjectiveKVDBStore - A persistent key-value store backed by ObjectiveKVDB.

Calling -init on INDANCSClient automatically initializes it using an instance of INDANCSObjectiveKVDBStore for persistent app metadata storage. If you want to use a different key-value store (or configure store file names, locations, etc.) you can use the initWithMetadataStore: initializer to pass in an object conforming to the INDANCSKeyValueStore protocol.

Contact

License

INDANCSClient is licensed under the MIT License.

More Repositories

1

InAppViewDebugger

A UIView debugger (like Reveal or Xcode) that can be embedded in an app for on-device view debugging
Swift
1,871
star
2

CocoaMarkdown

Markdown parsing and rendering for iOS and OS X
Objective-C
1,200
star
3

INAppStoreWindow

NSWindow subclass with a highly customizable title bar and traffic lights
Objective-C
1,064
star
4

DominantColor

Finding dominant colors of an image using k-means clustering
Swift
959
star
5

MarkdownTextView

Rich Markdown editing control for iOS
Swift
686
star
6

SwiftAutoLayout

Tiny Swift DSL for Autolayout
Swift
655
star
7

SNRHUDKit

Code drawn AppKit HUD interface elements
Objective-C
326
star
8

swiftrsrc

Resource code generation tool for Swift
Swift
290
star
9

INPopoverController

A customizable popover controller for OS X
Objective-C
196
star
10

SNRSearchIndex

SearchKit backed search for Core Data
Objective-C
190
star
11

Unzip

iOS 8 Action Extension for browsing ZIP files
Objective-C
165
star
12

NSUserNotificationPrivate

Private API showcase for NSUserNotification on OS X
Objective-C
152
star
13

SNRMusicKit

All-in-one framework for browsing and playing music from various sources on iOS and OS X
Objective-C
150
star
14

WWDC-2014

Scholarship submission for WWDC 2014
Objective-C
146
star
15

Ares

Zero-setup P2P file transfer between Macs and iOS devices
Swift
133
star
16

INDockableWindow

A window to which other views can be "docked" to and separated into their own windows
Objective-C
114
star
17

INDLinkLabel

A simple, no frills UILabel subclass with support for links
Swift
82
star
18

SNRFetchedResultsController

Automatic Core Data change tracking for OS X (NSFetchedResultsController port)
Objective-C
81
star
19

INDSequentialTextSelectionManager

Sequential text selection for NSTextViews
Objective-C
74
star
20

OEGridView

High performance Core Animation-based grid view, originally from OpenEmu.
Objective-C
72
star
21

INDGIFPreviewDownloader

[iOS] Retrieves preview images for GIFs by downloading only the first frame
Objective-C
60
star
22

Chip8

CHIP-8 emulator and disassembler written in Swift
Swift
53
star
23

pdfcat

OS X utility for concatenating PDF files
Swift
49
star
24

ReactiveXPC

Signals across process boundaries
Swift
36
star
25

ObjectiveKVDB

Objective-C wrapper for kvdb (https://github.com/dinhviethoa/kvdb)
Objective-C
33
star
26

SwiftTableViews

Type-safe Table Views with Swift
Swift
33
star
27

AlamofireRACExtensions

ReactiveCocoa Swift extensions for Alamofire
Swift
32
star
28

Dial

The beginnings of a replacement Contacts app for iOS.
Objective-C
30
star
29

ReactiveBLE

ReactiveCocoa wrapper for communicating with BLE devices using CoreBluetooth
Objective-C
29
star
30

INSOCKSServer

SOCKS5 proxy server implementation in Objective-C
Objective-C
27
star
31

LiveWebPreview

Web development tool for automatically refreshing a page when the content changes.
Objective-C
20
star
32

SNRLastFMEngine

[DEPRECATED] A modern block-based Objective-C interface to the Last.fm API
Objective-C
19
star
33

AttributedString.swift

Swift library that adds type safety and string interpolation support to NSAttributedString
Swift
18
star
34

INKeychainAccess

[DEPRECATED] Objective-C Keychain Services Wrapper for OS X and iOS
Objective-C
17
star
35

tecs

Projects for The Elements of Computing Systems by Nisan and Schocken
Assembly
15
star
36

INTrafficLightsDisabler

SIMBL plugin to hide the traffic lights on Mac OS X
Objective-C
14
star
37

pebble-lifx

Pebble controller for LIFX bulbs. UAlberta CompE Club Hackathon 2014 project.
Objective-C
11
star
38

xcode-themes

Color themes for Xcode 4 and 5
6
star
39

radars

Apple Radars filed for OS X and iOS.
Objective-C
5
star
40

indragiek.github.com

http://indragie.com
HTML
3
star
41

arduino-copter

Copter game for Arduino + Adafruit TFT
C++
2
star
42

writing

Things that I write
2
star
43

advent-of-code-2020

My Rust solutions for https://adventofcode.com
Rust
1
star
44

bootstrap-no-responsive

Compiled Bootstrap with responsive features disabled
1
star