I introduced “Factory Pattern” in my beacon scanning module. I referred http://crosbymichael.com/objective-c-design-patterns-factory.html
In my Factory class, 2 modes of beacons are switched between Interface classes “PCGoogleBeacon.h” and “PCAppleBeacon.h”.
//Header file of Factory
typedef enum beaconMode {
iBeacon,
Eddystone
} BeaconMode;
@interface PCBeaconFinder : NSObject
+(id) searchForBeaconMode:(BeaconMode) beaconMode;
@end
//Implementation of Factory
+(id) searchForBeaconMode:(BeaconMode) beaconMode
{
switch (beaconMode ) {
case iBeacon:
return [PCAppleBeacon new];
break;
case Eddystone:
return [PCGoogleBeacon new];
break;
default: NSLog(@"UNKOWN BEACON MODE");
}
}
In my Implementation file for interface classes.
//Header file
@protocol PCGetBeacon <NSObject>
-(void) scanBeaconsWithUUID:(NSString *) beaconId;
@end
//In the implementation file. — Implementation of Mode 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
// In the same above file— Implementation of Mode 2
#import "PCGoogleBeacon.h"
@implementation PCGoogleBeacon
-(void) scanBeaconsWithUUID:(NSString *) beaconId {
_scanner.delegate = self;
[_scanner startScanning];
NSLog(@"----------- > EDDYSTONE Implementation Called ");
}
//EDDYSTONE Delegates goes here …
@end
Everything is fine. Able to switch as from MainController,
id beaconFinderObject = [PCBeaconFinder searchForBeaconMode:iBeacon]; //or ‘Eddystone’ for Google beacon interface.
[beaconFinderObject scanBeaconsWithUUID:@"B0702880-A295-A8AB-F734-031A98A512DE"];
But why the delegates of corresponding classes are not called. ?
Note: Beacons are in the range.