I am making an iBeacon scanner plugin to use in different projects.
in myBeaconScanner.m file:
-(id)initWithUUID:(NSString *) _uuid{
self = [super init];
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:_uuid;
NSString *appID = [[NSBundle mainBundle] bundleIdentifier];
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:appID];
self.beaconRegion.notifyEntryStateOnDisplay = YES;
[self.locationManager startMonitoringForRegion:self.beaconRegion];
[self.locationManager requestAlwaysAuthorization];
[self locationManager:self.locationManager didStartMonitoringForRegion:self.beaconRegion];
UIUserNotificationType types = UIUserNotificationTypeAlert | UIUserNotificationTypeSound | UIUserNotificationTypeBadge;
UIUserNotificationSettings *mySettings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:mySettings];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
NSLog(@"started..");
return self;
}
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
[self sendLocalNotification:@"Welcome message.."]; **<-------------Line A**
}
Method to generate local notification:
-(void)sendLocalNotification:(NSString *)body{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = body;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
I know that every time the phone enters an iBeacon region this method is called:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
If under didFinishLaunchingWithOptions
I make an instance of my class (myBeaconScanner) then I call sendLocalNotification
I get the notification. However I want to make sure Line A works instead so that I don't have to call sendLocalNotification
method from elsewhere other than inside the class itself.