INDANCSClient

所属分类:C/C++基础
开发工具:Objective-C
文件大小:84KB
下载次数:0
上传日期:2014-01-12 19:34:32
上 传 者sh-1993
说明:  Objective-C Apple通知中心服务客户端
(Objective-C Apple Notification Center Service Client)

文件列表:
Common (0, 2014-01-13)
Common\INDANCSDefines.h (1110, 2014-01-13)
Examples (0, 2014-01-13)
Examples\INDANCSMac (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac.xcodeproj (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac.xcodeproj\project.pbxproj (24789, 2014-01-13)
Examples\INDANCSMac\INDANCSMac.xcodeproj\project.xcworkspace (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac.xcodeproj\project.xcworkspace\contents.xcworkspacedata (155, 2014-01-13)
Examples\INDANCSMac\INDANCSMac (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\Base.lproj (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\Base.lproj\MainMenu.xib (56016, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDANCSMac-Info.plist (1110, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDANCSMac-Prefix.pch (169, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDANCSNotificationTableCellView.h (398, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDANCSNotificationTableCellView.m (279, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDANCSNotificationTableRowView.h (271, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDANCSNotificationTableRowView.m (517, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDAppDelegate.h (302, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\INDAppDelegate.m (5500, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\Images.xcassets (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\Images.xcassets\AppIcon.appiconset (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\Images.xcassets\AppIcon.appiconset\Contents.json (903, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\en.lproj (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\en.lproj\Credits.rtf (436, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\en.lproj\InfoPlist.strings (45, 2014-01-13)
Examples\INDANCSMac\INDANCSMac\main.m (261, 2014-01-13)
Examples\INDANCSMac\INDANCSMacTests (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMacTests\INDANCSMacTests-Info.plist (692, 2014-01-13)
Examples\INDANCSMac\INDANCSMacTests\INDANCSMacTests.m (669, 2014-01-13)
Examples\INDANCSMac\INDANCSMacTests\en.lproj (0, 2014-01-13)
Examples\INDANCSMac\INDANCSMacTests\en.lproj\InfoPlist.strings (45, 2014-01-13)
Examples\INDANCSiPhone (0, 2014-01-13)
Examples\INDANCSiPhone\INDANCSiPhone.xcodeproj (0, 2014-01-13)
Examples\INDANCSiPhone\INDANCSiPhone.xcodeproj\project.pbxproj (22126, 2014-01-13)
Examples\INDANCSiPhone\INDANCSiPhone.xcodeproj\project.xcworkspace (0, 2014-01-13)
Examples\INDANCSiPhone\INDANCSiPhone.xcodeproj\project.xcworkspace\contents.xcworkspacedata (158, 2014-01-13)
Examples\INDANCSiPhone\INDANCSiPhone (0, 2014-01-13)
... ...

## INDANCSClient #### Objective-C Apple Notification Center Service Implementation ### Overview This is an Objective-C client and server implementation of the [Apple Notification Center Service](https://developer.apple.com/library/IOS/documentation/CoreBluetooth/Reference/AppleNotificationCenterServiceSpecification/Introduction/Introduction.html) (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](http://www.everymac.com/systems/by_capability/macs-with-bluetooth-different-bluetooth-capabilities.html) 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: ```obj-c - (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](https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html) 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](https://developer.apple.com/library/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/plist/info/UIBackgroundModes). ### 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`: ```obj-c #import 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: ```obj-c [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](https://github.com/indragiek/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 * Indragie Karunaratne * [@indragie](http://twitter.com/indragie) * [http://indragie.com](http://indragie.com) ### License `INDANCSClient` is licensed under the MIT License.

近期下载者

相关文件


收藏者