Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 如何限制通知的数量_Objective C_Uilocalnotification_Ibeacon - Fatal编程技术网

Objective c 如何限制通知的数量

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 *

我有3个独立的iBeacon放在3个不同的房间里。当进入信标区域时,didRangeBeacon方法每秒运行一次,从而在范围内产生无限多的通知

这是我的代码:

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

}