私は簡単なアプリケーションを作成しようとしています:
1. 利用可能な BTLE デバイスをスキャンし、
2. ユーザーが表示できるようにそれらをドロップダウン メニューに配置します。
これまでのところ、IOBluetooth フレームワークをインポートし、NSPopUpButton (結果を表示したい場所) への 1 つの IBOutlet と、startScan および stopScan というボタン用の 2 つの IBActions を用意しました。
私はしばらくそれをしていて、助けを求める必要があります. この素晴らしいフォーラムの他の投稿を見てきましたが、私は Objective-C プログラミングに比較的慣れていないので、あなたの助けにとても感謝しています。
これが私のインターフェースです:
#import <Cocoa/Cocoa.h>
#import <IOBluetooth/IOBluetooth.h>
@interface AppDelegate : NSObject <NSApplicationDelegate, CBCentralManagerDelegate, CBPeripheralDelegate> {
CBCentralManager * central; // these properties are for the CBCentralManager
CBPeripheral * peripheral;
NSMutableDictionary * dictionary;
NSNumber * number;
}
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSPopUpButton *deviceList;
@property NSMutableArray * list; // this is the array to fill up the deviceList NSPopUpButton
- (IBAction)startScan:(id)sender;
- (IBAction)stopScan:(id)sender;
@end
これが私の実装です:
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
CBCentralManager * central = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
NSLog(@"Central Manager's state is: %li", central.state);
}
- (IBAction)startScan:(id)sender {
// start scanning button
NSLog(@"Started scan. Discovering peripherals.");
NSArray * list;
}
- (IBAction)stopScan:(id)sender {
// stop scanning button
}
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
// I'm not sure how to make this work
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
NSLog(@"Central manager's state is updated to: %@", central);
}
- (void)retrievePeripherals:(NSArray *)peripheralUUIDs{
}
@end
私が言ったように、私はあなたの助けにとても感謝しています. 私はプログラミングが大好きですが、これには不満があります。あなたの 1 人がこれを見て、何が起こっているのかを正確に知っていると確信しています。
ありがとう、デビッド