ios – iBeacon – 應(yīng)用程序在區(qū)域啟動時未調(diào)用didEnterRegion

    我創(chuàng)建了一個注冊信標區(qū)域得應(yīng)用程序,并使用CLLocationManager開始監(jiān)視這些區(qū)域
    CLLocationManager *manager = [[CLLocationManager alloc] init];manager.delegate = self;CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:estimoteUUID major:12445 identifier:@"id"];region.notifyEntryStateOnDisplay = YES;region.notifyOnEntry = YES;[manager startMonitoringForRegion:region];

    當我從燈塔走得足夠遠并走回范圍時,這種方法很有效.但是,如果我已經(jīng)在信標區(qū)域得范圍內(nèi)啟動應(yīng)用程序,而不僅僅是當我回到邊界時,我還希望委托方法didEnterRegion可以觸發(fā).有沒有一種簡單得方法來實現(xiàn)這一目標?或者讓CLLocationManager認為我們離開了信標范圍得方法?

    另一篇帖子說設(shè)置region.notifyEntryStateOnDisplay = YES;并按下保持按鈕會這樣做 – 但我沒有這個工作(iOS 7.1,iPhone 5S).

    解決方法

    來自apple得文檔:

    Monitoring of a geographical region begins immediately after
    registration for authorized apps. However,don’t expect to receive an
    event right away,because only boundary crossings generate an event.
    In particular,if the user’s location is already inside the region
    at registration time,the location manager doesn’t automatically
    generate an event.
    Instead,your app must wait for the user to cross
    the region boundary before an event is generated and sent to the
    delegate. To check whether the user is already inside the boundary
    of a region,use the requestStateForRegion: method of the
    CLLocationManager class.

    所以我最終這樣做了:

    #import "ViewController.h"@interface ViewController ()@property (nonatomic,strong) NSDictionary *regionDictionary;@end@implementation ViewController- (void)viewDidLoad{    [super viewDidLoad];    // setup regions in case you have multiple regions    self.regionDictionary = @{@"com.test" : @"2FAE2A83-1634-443B-8A0C-56704F81A181"};    // setup location manager    self.locationManager = [[CLLocationManager alloc] init];    self.locationManager.delegate = self;    if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {        [self.locationManager requestAlwaysAuthorization];    }    [self.locationManager startUpdatingLocation];    //start monitoring for all regions    for (NSString *key in self.regionDictionary.allKeys) {        CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:self.regionDictionary[key]] identifier:key];        [self.locationManager startMonitoringForRegion:beaconRegion];    }}- (void)locationManager:(CLLocationManager*)manager didEnterRegion:(CLRegion *)region {    if (region.identifier.length != 0) {        CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:self.regionDictionary[region.identifier]] identifier:region.identifier];        [self.locationManager startRangingBeaconsInRegion:beaconRegion];    }}- (void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion *)region {    if (region.identifier.length != 0) {        CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:self.regionDictionary[region.identifier]] identifier:region.identifier];        [self.locationManager stopRangingBeaconsInRegion:beaconRegion];    }}- (void)locationManager:(CLLocationManager*)manager didRangeBeacons:(NSArray*)beacons inRegion:(CLBeaconRegion*)region {    // Beacon found!    CLBeacon *foundBeacon = [beacons firstObject];    NSLog(@"UUID:%@; major:%@; minor:%@;",foundBeacon.proximityUUID.UUIDString,foundBeacon.major,foundBeacon.minor); }- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {    if ([region isKindOfClass:[CLBeaconRegion class]] && state == CLRegionStateInside) {        [self locationManager:manager didEnterRegion:region];    }}- (void)locationManager:(CLLocationManager *) manager didStartMonitoringForRegion:(CLRegion *) region {    [manager requestStateForRegion:region];}

    以上是來客網(wǎng)為你收集整理得ios – iBeacon – 應(yīng)用程序在區(qū)域啟動時未調(diào)用didEnterRegion全部內(nèi)容,希望內(nèi)容能夠幫你解決ios – iBeacon – 應(yīng)用程序在區(qū)域啟動時未調(diào)用didEnterRegion所遇到得程序開發(fā)問題。

    如果覺得來客網(wǎng)網(wǎng)站內(nèi)容還不錯,歡迎將來客網(wǎng)網(wǎng)站推薦給程序員好友。

    聲明:所有內(nèi)容來自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進行處理。
    發(fā)表評論
    更多 網(wǎng)友評論1 條評論)
    暫無評論

    返回頂部

    主站蜘蛛池模板: 国产aⅴ精品一区二区三区久久 | 日韩AV无码一区二区三区不卡毛片 | 午夜在线视频一区二区三区| 日韩免费视频一区| 免费无码VA一区二区三区| 无人码一区二区三区视频| 亚洲精品日韩一区二区小说| 日韩精品乱码AV一区二区| 日本欧洲视频一区| 高清一区二区三区日本久| 日韩人妻无码一区二区三区久久99| 在线电影一区二区| 日韩AV片无码一区二区不卡| 精品动漫一区二区无遮挡| 色妞AV永久一区二区国产AV| 黄桃AV无码免费一区二区三区| 日本精品一区二区久久久| 国产精品va一区二区三区| 国产一区二区影院| 国产麻豆媒一区一区二区三区| 无码丰满熟妇一区二区| 日本一区二区三区免费高清| 欧美日本精品一区二区三区| 无码人妻精一区二区三区| 国产日韩一区二区三区在线播放 | 国产成人精品日本亚洲专一区 | 国产亚洲情侣一区二区无码AV| 国产aⅴ一区二区| 精品视频一区二区三区四区五区| 久久精品无码一区二区app | 精品欧美一区二区在线观看| 国产精品一区二区久久精品涩爱| 亚洲一区二区三区不卡在线播放| 日日摸夜夜添一区| 日美欧韩一区二去三区| 日本精品一区二区三区四区| 国产精品一区二区av| 国产成人综合一区精品| 精品人妻一区二区三区四区 | 久久影院亚洲一区| 文中字幕一区二区三区视频播放|