MaBeeeApp - novars-jp/MaBeeeiOSSDK GitHub Wiki
概要
MaBeeeAppクラスはこのSDKの中心となるクラスです。 このクラスには以下のような機能があります。
- iOSデバイスのBluetoothの管理 (CoreBluetooth/CBCentralManagerの保持・管理)
- MaBeeeのスキャン・接続
- MaBeeeDeviceオブジェクトの生成・管理
- MaBeeeDeviceおよびBluetoothの状態などの通知
インスタンスの取得
instance
MaBeeeAppのシングルトンのインスタンスを取得します。
Objective-C
+ (MaBeeeApp *)instance;
Swift
public class func instance() -> MaBeeeApp!
- 初回呼び出し時には生成も行ないます。
- 生成時にCBCentralManagerのインスタンス化・初期化も行ないます。
- 2回め以降の呼び出しは単にグローバル変数のインスタンスを返すだけです。
finalizeApp
MaBeeeAppのインスタンスのリソースの解放を行ないます。
Objective-C
- (void)finalizeApp;
Swift
public func finalizeApp()
- 通常使いません。
- 今後消す予定です。
iOSデバイスのBluetoothの状態取得
centralManagerState
CBCentralManager/stateを返します。
Objective-C
- (CBCentralManagerState)centralManagerState;
Swift
public func centralManagerState() -> CBCentralManagerState
- 値の詳細はこちらを参照してください。
- この値により、iOSデバイスのBluetoothの状態が取得できます。
- この値が変更された場合、例えばユーザがBluetoothをオフにした場合などは、MaBeeeCentralManagerDidUpdateNotificationが通知されます。
MaBeeeDeviceのスキャン
startScan
スキャンを開始します。
Objective-C
- (void)startScan:(MaBeeeScanHandler)scanHandler;
Swift
public func startScan(scanHandler: MaBeeeScanHandler!)
- scanHandler
- MaBeeeScanHandler
- スキャン時に更新データを受け取るハンドラです。
- MaBeeeDeviceが追加・削除された場合に呼び出されます。
- 引数のdevicesをテーブルビューに表示するなどが可能です。
MaBeeeScanHandler
スキャン時に更新データを受け取るハンドラです。
Objective-C
typedef void (^MaBeeeScanHandler)(NSArray<MaBeeeDevice *> *devices);
Swift
public typealias MaBeeeScanHandler = ([MaBeeeDevice]!) -> Void
- startScanの引数のハンドラの型です。
stopScan
スキャンを停止します。
Objective-C
- (void)stopScan;
Swift
public func stopScan()
isScanning
現在のスキャンしているかを返します。
Objective-C
- (BOOL)isScanning;
Swift
public func isScanning() -> Bool
- スキャン中の場合はYES/ture, スキャンしていない場合はNO/falseを返します。
MaBeeeDeviceの取得
devices
MaBeeeAppが管理するMaBeeeDeviceの配列を返します。
Objective-C
- (NSArray<MaBeeeDevice *> *)devices;
Swift
public func devices() -> [MaBeeeDevice]!
- スキャン時はスキャンで発見したMaBeeeDeviceオブジェクトも含まれます。
- スキャンしていない時は、接続あるいは接続しようとしているMaBeeeDeviceオブジェクトのみとなります。
deviceWithIdentifier
デバイスのIDに対するデバイスを返します。
Objective-C
- (MaBeeeDevice *)deviceWithIdentifier:(NSUInteger)identifier;
Swift
public func deviceWithIdentifier(identifier: UInt) -> MaBeeeDevice!
- 存在しない場合はnilを返します。
MaBeeeDeviceとの接続
connect
MaBeeeDeviceに接続します。
Objective-C
- (void)connect:(MaBeeeDevice *)device;
Swift
public func connect(device: MaBeeeDevice!)
- 引数
- device
- 接続するMaBeeeDeviceオブジェクト
- device
disconnect
MaBeeeDeviceを切断します。
Objective-C
- (void)disconnect:(MaBeeeDevice *)device;
Swift
public func disconnect(device: MaBeeeDevice!)
- 引数
- device
- 切断するMaBeeeDevice
- device
- この関数で切断したMaBeeeDeviceを再取得するには、スキャンする必要があります。
通知の設定
addObserver
MaBeeeAppからの通知を受け取るオブジェクトとセレクタを追加します。
Objective-C
- (void)addObserver:(id)observer selector:(SEL)selector;
Swift
public func addObserver(observer: AnyObject!, selector: Selector)
- 引数
- observer
- 通知を受け取るオブジェクトを指定します。
- selector
- 通知を受け取る関数を指定します。
- observer
- 通常はUIViewControllerのviewDidAppearなどで設定します。
removeObserver
MaBeeeAppの通知を受け取るオブジェクトを削除します。
Objective-C
- (void)removeObserver:(id)observer;
Swift
public func removeObserver(observer: AnyObject!)
- 引数
- observer
- 削除対象のオブジェクト
- observer
- 通常はUIViewControllerのviewWillDisappearなどで削除します。
MaBeeeCentralManagerDidUpdateNotification
CBCentralManager/stateが変更されたときの通知です。
Objective-C
extern NSString *MaBeeeCentralManagerDidUpdateNotification;
Swift
public let MaBeeeCentralManagerDidUpdateNotification: String
- userInfoに"CBCentralMangaerState"というキーで、変更後の値が格納されています。
MaBeeeDeviceDidConnectNotification
MaBeeeへの接続が完了したときの通知です。
Objective-C
extern NSString *MaBeeeDeviceDidConnectNotification;
Swift
public let MaBeeeDeviceDidConnectNotification: String
- userInfoに"MaBeeeDeviceIdentifier"というキーで、接続が完了したMaBeeeDeviceのidentifierが格納されています。
MaBeeeDeviceDidDisconnectNotification
MaBeeeとの接続が解除されたときの通知です。
Objective-C
extern NSString *MaBeeeDeviceDidDisconnectNotification;
Swift
public let MaBeeeDeviceDidDisconnectNotification: String
- userInfoに"MaBeeeDeviceIdentifier"というキーで、接続が解除されたしたMaBeeeDeviceのidentifierが格納されています。
MaBeeeDeviceRssiDidUpdateNotification
RSSIが更新されたときの通知です。
Objective-C
extern NSString *MaBeeeDeviceRssiDidUpdateNotification;
Swift
public let MaBeeeDeviceRssiDidUpdateNotification: String
- userInfoに"MaBeeeDeviceIdentifier"というキーで、RSSIが更新されたMaBeeeDeviceのidentifierが格納されています。
MaBeeeDeviceBatteryVoltageDidUpdateNotification
BatteryVoltageが更新されたときの通知です。
Objective-C
extern NSString *MaBeeeDeviceBatteryVoltageDidUpdateNotification;
Swift
public let MaBeeeDeviceBatteryVoltageDidUpdateNotification: String
- userInfoの"MaBeeeDeviceIdentifier"というキーで、BatteryVoltageが更新されたMaBeeeDeviceのidentifierが格納されています。