Я делаю плагин iBeacon scanner для использования в разных проектах.iOS: вызов метода внутри класса
в myBeaconScanner.m файле:
-(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**
}
метод для создания локального уведомления:
-(void)sendLocalNotification:(NSString *)body{
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = body;
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];
}
Я знаю, что каждый раз, когда телефон входит в область IBeacon этот метод называется:
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
Если под didFinishLaunchingWithOptions
Я делаю экземпляр моего класса (myBeaconScanner), затем я звоните sendLocalNotification
Получаю уведомление. Однако я хочу убедиться, что Линия A работает вместо этого, поэтому мне не нужно вызывать метод sendLocalNotification
из другого места, кроме самого класса.