2016-03-23 26 views
0

以下是我的代碼,它正在檢測信標,但是在後臺它不發送通知。 任何人都可以追查究竟是用代碼來自Beacon iOS的使用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

+0

您使用iBeacon顯示或eddystore配置? –

回答

0

添加requestWhenInUseAuthorization我懷疑你的應用程序沒有被授予位置權限。要驗證,請轉到設置 - >並檢查您的應用是否具有「始終」位置權限。如果是這樣,它應該看起來像下面的屏幕截圖。

如果您沒有授予位置訪問權限,請檢查您的代碼請求。除了在你的plist中的條目,你需要的東西是這樣的:

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

enter image description here