我正在尝试为我的BLEManager创建一个单例类,它在启动屏幕ViewController的viewdidload上调用。在init完成后,如何在视图控制器中获取对象_transporter和_BLEAdapter?
BLEManager.h
@interface MyManager : NSObject {
BLETransporter* _transporter;
BLEAdapter* _BLEAdapter;
}
@property (strong, nonatomic) BLETransporter* transporter;
@property (strong, nonatomic) BLEAdapter* BLEAdapter;
+ (id)sharedInstance;
@end
BLEManager.m
@implementation MyManager
@synthesize BLEAdapter=_BLEAdapter;
@synthesize transporter = _BLEAdapter;
+(BLEManager*)sharedInstance{
static BLEManager *sharedInstance = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
- (id)init {
if (self = [super init]) {
_transporter = [BLETransporter transporterWithIdentifier:nil serviceUUIDs:serviceUUIDs];
[_transporter connectWithBlock:^(NSInputStream * _Nullable inputStream, NSOutputStream * _Nullable outputStream) {
if ( !inputStream )
{
LOG( @"Could not connect to device" );
return;
}
_BLEAdapter = [BLEAdapter adapterWithInputStream:inputStream outputStream:outputStream];
[_BLEAdapter connect];
}];
}
return self
}