使用 ESTBeaconManager 来自 Beacon iOS 的后台通知

Background Notification from Beacon iOS using 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 位置服务授权不足。监控将暂停,直到授予适当的授权。"

虽然我在信息 plist 中添加了 requestWhenInUseAuthorization

我怀疑您的应用未被授予位置权限。要验证,请转到设置 -> 并检查您的应用是否具有 "Always" 位置权限。如果是这样,它应该类似于下面的屏幕截图。

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

if([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
  [locationManager requestAlwaysAuthorization];
}