我正在尝试编写一个简单的应用程序:
1.扫描可用的BTLE设备,然后
2.将它们放在下拉菜单中供用户查看.
到目前为止,我已经导入了IOBluetooth框架,我有一个IBOutlet到NSPopUpButton(我想显示结果)和两个IBAction用于按钮,名为startScan和stopScan.
我已经有一段时间了,我需要寻求帮助.我在这个精彩的论坛上看到了其他帖子,但我对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
Run Code Online (Sandbox Code Playgroud)
这是我的实现:
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to …Run Code Online (Sandbox Code Playgroud)