Objective c 如何限制通知的数量
我有3个独立的iBeacon放在3个不同的房间里。当进入信标区域时,didRangeBeacon方法每秒运行一次,从而在范围内产生无限多的通知 这是我的代码:Objective c 如何限制通知的数量,objective-c,uilocalnotification,ibeacon,Objective C,Uilocalnotification,Ibeacon,我有3个独立的iBeacon放在3个不同的房间里。当进入信标区域时,didRangeBeacon方法每秒运行一次,从而在范围内产生无限多的通知 这是我的代码: BOOL _isInsideRegion; - (void)locationManager:(CLLocationManager*)manager didRangeBeacons:(NSArray*)beacons inRegion:(CLBeaconRegion*)region { CLBeacon *
BOOL _isInsideRegion;
- (void)locationManager:(CLLocationManager*)manager didRangeBeacons:(NSArray*)beacons inRegion:(CLBeaconRegion*)region {
CLBeacon *firstBeacon = [beacons firstObject];
int major = [firstBeacon.major intValue];
int minor = [firstBeacon.minor intValue];
if (major == 43005 && minor == 52679) {
if (!_isInsideRegion) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.soundName = @"Default";
notification.alertBody = @"Green";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
self.beaconColour.text = @"Green";
self.minor.text = [NSString stringWithFormat:@"%D", minor];
self.major.text = [NSString stringWithFormat:@"%D", major];
}
}
else if (major == 48891 && minor == 47852) {
if (!_isInsideRegion) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.soundName = @"Default";
notification.alertBody = @"blue";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
self.beaconColour.text = @"Blue";
self.minor.text = [NSString stringWithFormat:@"%D", minor];
self.major.text = [NSString stringWithFormat:@"%D", major];
}
}
else if (major == 59510 && minor == 42953) {
if (!_isInsideRegion) {
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.soundName = @"Default";
notification.alertBody = @"dark blue";
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
self.beaconColour.text = @"Dark Blue";
self.minor.text = [NSString stringWithFormat:@"%D", minor];
self.major.text = [NSString stringWithFormat:@"%D", major];
}
}
}
有谁能帮助我,让它在进入时发出一个通知,然后当我走到下一个信标时,我会收到另一个特定于该信标的通知。
谢谢。使用
locationManager:didEnterRegion:
方法
当用户输入应用程序定义的信标区域时,将调用此方法
- (void)locationManager:(CLLocationManager *)manager
didEnterRegion:(CLBeaconRegion *)region {
NSLog(@"Did Enter Region for %@", region.identifier);
//Show Notification
}