簡體   English   中英

在iOS 8中無法檢測到iBeacon

[英]Can't detect iBeacon in iOS 8

我已經跟隨AppCodaDevfright的在線教程創建了一個iBeacon檢測應用程序。 我正在使用來自estimote的iBeacon,這是一款支持iOS 8的iPad 3.該應用程序根本無法檢測到我的iBeacon,而其他iBeacon應用程序正在檢測它。 我無法理解我在代碼中遺漏或做錯了什么。

這是我的.h文件:

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface ViewController : UIViewController<CLLocationManagerDelegate>

@property (nonatomic, strong) CLBeaconRegion   *beaconRegion;
@property (nonatomic, strong) CLLocationManager *locManager;

@property (nonatomic, strong) IBOutlet UILabel *label1;
@property (nonatomic, strong) IBOutlet UILabel *label2;

@end

這是我的.m文件:

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>

@interface ViewController () <CLLocationManagerDelegate>

@end

@implementation ViewController


- (void)viewDidLoad {
[super viewDidLoad];

self.locManager = [[CLLocationManager alloc] init];
self.locManager.delegate = self;

//default uuid for estimote beacons
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"B9407F30-F5F8-466E-AFF9-25556B57FE6D"];

self.beaconRegion = [[CLBeaconRegion alloc]initWithProximityUUID:uuid identifier:@"com.rk.testregion"];

[self.locManager startMonitoringForRegion:self.beaconRegion];
[self locationManager:self.locManager didStartMonitoringForRegion:self.beaconRegion];

// Check if beacon monitoring is available for this device
if (![CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) {

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Monitoring not available" message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil]; [alert show]; return;
}

}

-(void)locationManager:(CLLocationManager*)manager didRangeBeacons:(NSArray*)beacons inRegion:(CLBeaconRegion*)region
{
// Beacon found!
self.label1.text = @"Welcome to";
self.label2.text = @"Location 1";

CLBeacon *foundBeacon = [beacons firstObject];

// retrieve the beacon data from its properties
NSString *uuid = foundBeacon.proximityUUID.UUIDString;
NSString *major = [NSString stringWithFormat:@"%@", foundBeacon.major];
NSString *minor = [NSString stringWithFormat:@"%@", foundBeacon.minor];

NSLog(@"UUID: %@", uuid);
NSLog(@"major: %@", major);
NSLog(@"minor: %@", minor);

}

- (void)viewDidDisappear:(BOOL)animated
{
[self.locManager stopRangingBeaconsInRegion:self.beaconRegion];

[super viewDidDisappear:animated];
}

- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion*)region
{
[self.locManager startRangingBeaconsInRegion:self.beaconRegion];
}

-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion*)region
{
[self.locManager stopRangingBeaconsInRegion:self.beaconRegion];
self.label1.text = @"Searching again...";
}

- (void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region {

[self.locManager startRangingBeaconsInRegion:self.beaconRegion];
}

@end

委托方法didRangeBeacons根本沒有被調用。 有人可以讓我知道如何解決這個問題。

看看下面的答案,其中描述了一些額外的箍,你現在需要跳過才能實現這個目的:

位置服務在iOS 8中不起作用

完全披露:我自己沒試過。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM