如何用灯塔解决问题?

时间:2016-04-24 10:24:02

标签: ios objective-c ibeacon beacon

我的问题:当我点击按钮时,我的手机会显示进度视图(让我关闭信标),当我关闭信标时,我的手机会显示一个视图(选中标记),然后删除查看1.5s后。现在视图可以正常显示,但是当我将手机远离信标时,视图(显示复选标记)将在1秒后显示。这是我脑海中的一个大问题。 我的代码:

onClick按钮

- (IBAction)chooseBLEAction:(id)sender {
    self.locationManager = [CLLocationManager new];
    [self _initBeaconRegion];

    if (([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse ||
         [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways ||
         [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) &&
        [self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
    {
        [self _start];

        if (self.bluetoothIsOpen) {
            [self _createProgressView];
        }
    }else {
        [self.locationManager requestWhenInUseAuthorization];
    }
}

- (void)_start {
    [self.locationManager startRangingBeaconsInRegion:self.targetBeaconRegion];
}

- (void)_stop {
    [self.locationManager stopRangingBeaconsInRegion:self.targetBeaconRegion];
}

CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray<CLBeacon *> *)beacons inRegion:(CLBeaconRegion *)region {
    NSLog(@"searching for beacon !");

    CLBeacon *foundBeacon = [CLBeacon new];
    foundBeacon = [beacons firstObject];
    if (foundBeacon) {
        NSLog(@"found beacon !");

        switch (foundBeacon.proximity) {
            case CLProximityUnknown:
                break;

            case CLProximityFar:
                break;

            case CLProximityNear:
                break;

            case CLProximityImmediate:
            {
                [self _stop];
                NSLog(@"Immediate beacon !");
                AudioServicesPlaySystemSound(1051);

                [self.myProgressView removeFromSuperview];
                [self _createSuceessProgressView];

                self.removeProgressViewTimer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(_removeSuccessProgressView) userInfo:nil repeats:NO];

                break;
            }
        }
    }
}

创建进度视图(关闭信标)

- (void)_createProgressView {
    NSString *title = @"Please close the beacon";
    self.myProgressView = [MRProgressOverlayView showOverlayAddedTo:self.view title:title mode:MRProgressOverlayViewModeIndeterminate animated:YES];
}

创建成功视图

- (void)_createSuceessProgressView {
    NSString *title = @"Success!";
    self.suceessProgressView = [MRProgressOverlayView showOverlayAddedTo:self.view title:title mode:MRProgressOverlayViewModeCheckmark animated:YES];
}

1.5s之后删除成功视图

- (void)_removeSuccessProgressView {
    [self.removeProgressViewTimer invalidate];
    [self.suceessProgressView removeFromSuperview];
}

0 个答案:

没有答案