ios – iBeacon – 應用程序在區域啟動時未調用didEnterRegion

    我創建了一個注冊信標區域得應用程序,并使用CLLocationManager開始監視這些區域
    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];

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

    另一篇帖子說設置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];}

    以上是來客網為你收集整理得ios – iBeacon – 應用程序在區域啟動時未調用didEnterRegion全部內容,希望內容能夠幫你解決ios – iBeacon – 應用程序在區域啟動時未調用didEnterRegion所遇到得程序開發問題。

    如果覺得來客網網站內容還不錯,歡迎將來客網網站推薦給程序員好友。

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

    返回頂部

    主站蜘蛛池模板: 亚洲一区二区三区夜色| 色狠狠AV一区二区三区| 久久国产精品免费一区| 亚洲一区二区三区精品视频| 国产精品福利一区| 在线精品国产一区二区| 精品一区二区无码AV| 精品在线一区二区| 无码少妇丰满熟妇一区二区| 亚洲高清日韩精品第一区| 一区二区三区无码视频免费福利| 精品免费AV一区二区三区| 国产成人一区二区三区电影网站| 精品国产一区二区三区麻豆| 麻豆一区二区三区精品视频| 日韩人妻一区二区三区蜜桃视频 | 国产精品自拍一区| 骚片AV蜜桃精品一区| 无码人妻久久久一区二区三区| 国产一区二区视频在线播放| 久久se精品一区精品二区国产| 免费无码一区二区| 日本一区二区三区在线网| 国产亚洲综合精品一区二区三区 | 无码喷水一区二区浪潮AV| 97一区二区三区四区久久| 日韩国产精品无码一区二区三区| 精品久久一区二区三区| 国产精品成人国产乱一区| 一区二区三区波多野结衣| 精品视频一区二区| 中文日韩字幕一区在线观看| 中文字幕无码一区二区三区本日| 国产一区二区三区免费观在线| 精品国产免费一区二区三区香蕉| 91在线视频一区| 国产亚洲福利一区二区免费看| 午夜视频久久久久一区 | 无码人妻一区二区三区在线 | 精品国产a∨无码一区二区三区 | 久久精品无码一区二区三区|