来自Beacon iOS的背景通知使用ESTBeaconManager

时间:2016-03-23 03:56:54

标签: ios ibeacon estimote estbeaconmanager

以下是我的代码,它正在检测信标,但在后台时它不会发送通知。 任何人都可以跟踪代码的确切问题

@property (nonatomic) ESTBeaconManager *beaconManager;
@property (strong, nonatomic) CLBeaconRegion *beacRegion;
@property (strong, nonatomic) NSArray *estimoteBeacons;
- (void)viewDidLoad {
 self.beaconManager = [ESTBeaconManager new];
self.beaconManager.delegate = self;
self.beaconManager.returnAllRangedBeaconsAtOnce = YES;


 self.beacRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"xxxxxx-xxxx-xxxx-xxxx-..."] major:000 minor:0000 identifier:[NSString stringWithFormat:@"%@", @"HEY GUYS!"]];
    [self.beaconManager startRangingBeaconsInRegion:self.beacRegion];
[self.beaconManager startMonitoringForRegion:self.beacRegion];

}

- (void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region
{
NSLog(@"didEnterRegion");
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"You have entered the region you are monitoring";
localNotification.soundName =  UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];}

    - (void)beaconManager:(id)manager didEnterRegion:(CLBeaconRegion *)region
{
NSLog(@"didEnterRegion");
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.alertBody = @"You have left the region you are monitoring";
localNotification.soundName =  UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]presentLocalNotificationNow:localNotification];}

当我看到设备的堆栈跟踪时,我收到此消息:

" -iPhone ESTBeacon [1366]:monitoringDidFailForRegion位置服务授权不足。监控将暂停,直到授予适当的授权。"

虽然我在info plist

中添加了requestWhenInUseAuthorization

1 个答案:

答案 0 :(得分:1)

我怀疑您的应用尚未获得位置权限。要验证,请转到设置 - >并检查您的应用是否有"始终"位置许可。如果是,它应该如下面的截图。

如果您没有授予位置访问权限,请检查请求它的代码。除了你的plist中的条目,你还需要这样的东西:

<header>
  <h1>Title</h1>
  <h2>title</h2>
  <nav>
    <ul id="menu">
      <li><a href="#">Home</a></li>
      <li><a href="#">Home</a></li>
      <li><a href="#">Home</a></li>
      <li><a href="#">Home</a></li>
    </ul>
  </nav>
</header>
<div id="container">
  <img class="fig" src="https://www.organicfacts.net/wp-content/uploads/2013/05/watermelon2.jpg" alt="figure 1">
</div>

enter image description here