0
我在信标扫描模块中引入了“工厂模式”。我称为http://crosbymichael.com/objective-c-design-patterns-factory.html工厂模式:iBeacon代表未从实施文件中调用
以我Factory类,信标2种模式接口类“PCGoogleBeacon.h”和“PCAppleBeacon.h”之间进行切换。工厂
的//头文件
typedef enum beaconMode {
iBeacon,
Eddystone
} BeaconMode;
@interface PCBeaconFinder : NSObject
+(id) searchForBeaconMode:(BeaconMode) beaconMode;
@end
//实现工厂
+(id) searchForBeaconMode:(BeaconMode) beaconMode
{
switch (beaconMode) {
case iBeacon:
return [PCAppleBeacon new];
break;
case Eddystone:
return [PCGoogleBeacon new];
break;
default: NSLog(@"UNKOWN BEACON MODE");
}
}
的在为接口类我实现文件。
//Header file
@protocol PCGetBeacon <NSObject>
-(void) scanBeaconsWithUUID:(NSString *) beaconId;
@end
//在执行文件中。 - 模式1
#import "PCAppleBeacon.h"
@implementation PCAppleBeacon
-(void) scanBeaconsWithUUID:(NSString *) beaconId {
self.proximityContentManager = [[ProximityContentManager alloc]
initWithBeaconIDs:@[
[[BeaconID alloc] initWithUUIDString:beaconId major:0 minor:0]
]
beaconContentFactory:[EstimoteCloudBeaconDetailsFactory new]];
self.proximityContentManager.delegate = self;
[self.proximityContentManager startContentUpdates];
NSLog(@"----------- > iBeacon Implementation Called ");
}
//iBeacon Delegates goes here …
@end
//的
实现在模式2中的一切#import "PCGoogleBeacon.h"
@implementation PCGoogleBeacon
-(void) scanBeaconsWithUUID:(NSString *) beaconId {
_scanner.delegate = self;
[_scanner startScanning];
NSLog(@"----------- > EDDYSTONE Implementation Called ");
}
//EDDYSTONE Delegates goes here …
@end
与上述相同文件级实现优良。能够切换从MainController,
id beaconFinderObject = [PCBeaconFinder searchForBeaconMode:iBeacon]; //or ‘Eddystone’ for Google beacon interface.
[beaconFinderObject scanBeaconsWithUUID:@"B0702880-A295-A8AB-F734-031A98A512DE"];
那为什么不叫相应的类的代表。 ?
注:信标在该范围内。
对于'[PCGoogleBeacon scanBeaconsWithUUID:]',它看起来像beaconId被丢弃。对于'PCAppleBeacon',它被设置为主/次0/0。你确定他们被配置为扫描正确的信标编号吗? – ama1111
@ ama111是的,我向你保证MacBeacon(OSX)应用程序用于与上述UUID,主要和次要的广播。感谢您的回复 – byJeevan
它工作正常,如果我删除工厂设计模式后在MainViewController类中添加委托。 – byJeevan