iBeacon使用粒子。接近触发不起作用

时间:2014-05-30 14:19:00

标签: objective-c xcode5 ibeacon

我让粒子ibeacon进入和离开一个区域。我离开我的房子它说安全,我回家,它迎接我。我设置了这张桌子,所以当我不知道,远近,立即时,相应的反应告诉我我的牢房。我正在使用此开关

switch (proximity) {
        case CLProximityUnknown:
            return @"unknown";
            NSLog(@"This is the cell talking");
            break;
        case CLProximityImmediate:
            return @"Immediate";
            NSLog(@"This is immediate cell talking");
            break;
        case CLProximityNear:
            return @"Near";
            break;
        case CLProximityFar:
            return @"Far";
        default:
            break;
}

这很完美。所以在我的主视图控制器中我添加了这个

-(void)actionForProximity:(CLProximity)proximity
{
    UILocalNotification *notification = [[UILocalNotification alloc]init];

    switch (proximity) {
        case CLProximityImmediate:
            notification.alertBody = @"You are in immediate danger!";
            notification.soundName = @"Default";
            [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
            NSLog(@"You are in immediate proximity to the beacon");
            break;
        case CLProximityNear:
            notification.alertBody = @"You are very near";
            notification.soundName = @"Default";
            [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
            NSLog(@"You are near the beacon");
            break;
        case CLProximityFar:
            notification.alertBody = @"Where are you going, you may get lost";
            notification.soundName = @"Default";
            [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
            NSLog(@"You are far from the beacon");
        default:
            break;
    }
}

但它似乎根本不会引发触发。我使用了一个断点,它似乎根本没有达到这个方法。我真的想使用邻近触发弹出窗口或应用程序控制器等...任何帮助将非常感激。感谢您抽出宝贵时间阅读。

1 个答案:

答案 0 :(得分:1)

您的切换(邻近)应该在您的委托方法中。

-(void)beaconManager:(ESTBeaconManager *)manager
     didRangeBeacons:(NSArray *)beacons
            inRegion:(ESTBeaconRegion *)region

DidRangeBeacons需要一系列信标。

方法

  

[self.beaconManager startRangingBeaconsInRegion:region]

返回您需要的数组,并且应该在ViewDidAppear

我认为委托方法每20毫秒触发一次。

希望这可以帮到你。

(我正在使用Estimote SDK)