-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathUUAccessorySession.h
More file actions
59 lines (44 loc) · 2.1 KB
/
UUAccessorySession.h
File metadata and controls
59 lines (44 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// UUAccessorySession.h
// Useful Utilities - Simple client for communicating with an external accessory
//
// Created by Ryan on 02/01/16
//
// License:
// You are free to use this code for whatever purposes you desire. The only requirement is that you smile everytime you use it.
//
#import <Foundation/Foundation.h>
#import <ExternalAccessory/ExternalAccessory.h>
typedef void (^UUAccessoryConnectCallback)(NSError* error);
typedef void (^UUAccessoryWriteDataCallback)(NSError* error);
typedef void (^UUAccessoryReadDataCallback)(NSError* error, NSData* data);
typedef void (^UUAccessoryPushedDataCallback)(NSData* data);
@interface UUAccessorySession : NSObject
- (id) initWithProtocol:(NSString*)protocol;
- (BOOL) isConnected;
- (void) connect:(UUAccessoryConnectCallback)completion;
- (void) writeData:(NSData*)data completion:(UUAccessoryWriteDataCallback)completion;
- (void) readData:(NSUInteger)count timeout:(NSTimeInterval)timeout completion:(UUAccessoryReadDataCallback)completion;
// Some accessories will just push data to the phone. This provides a raw data pipe
// where the accessory data will be passed along.
//
// NOTE: This callback will only be invoked if there is no current call to readData that
// is waiting for data to come in.
- (void) registerPushedDataCallback:(UUAccessoryPushedDataCallback)callback;
@end
extern NSString * const kUUAccessorySessionErrorDomain;
typedef NS_ENUM(NSInteger, UUAccessorySessionErrorCode)
{
UUAccessorySessionErrorCodeBluetoothPickerError = 1000,
UUAccessorySessionErrorCodeUnableToCreateAccessory,
UUAccessorySessionErrorCodeUnableToAcquireInputStream,
UUAccessorySessionErrorCodeUnableToOpenInputStream,
UUAccessorySessionErrorCodeUnableToAcquireOutputStream,
UUAccessorySessionErrorCodeUnableToOpenOutputStream,
UUAccessorySessionErrorCodeNoDeviceFound,
UUAccessorySessionErrorCodeNoDeviceFoundReadDataTimeout
};
@interface NSError (UUAccessorySession)
+ (instancetype) uuAccessorySessionError:(UUAccessorySessionErrorCode)code;
+ (instancetype) uuAccessorySessionError:(UUAccessorySessionErrorCode)code inner:(NSError*)inner;
@end