2014-09-29 21 views
0

以下是代码片段。下面。iOS 8:区域监控,如何使其工作

// Initialize the region with the Estimote iBeacon manually generated UUID of 16 bytes size. 
NSUUID *estimoteUUID = [[NSUUID alloc] initWithUUIDString:[Repository getiBeaconRegionUUID]]; 
_beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:estimoteUUID 
                identifier:@"A"]; 

// Launch app when display is turned on and inside region. 
_beaconRegion.notifyEntryStateOnDisplay = YES; 

// Create a location manager 
_locationManager = [[CLLocationManager alloc] init]; 
// Set delegate 
_locationManager.delegate = self; 
if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) 
{ 
    [_locationManager requestAlwaysAuthorization]; 

    [_locationManager startMonitoringForRegion:_beaconRegion]; 

    // Get status update right away for UI 
    [_locationManager requestStateForRegion:_beaconRegion]; 
} 
else 
    NSLog(@"This device does not support monitoring beacon regions"); 

NSLocationAlwaysUsageDescription添加到应用程序。 plist中。

从来没有从上面的密钥文本的对话框。

在设置=>隐私=>应用程序的位置服务。在第一个应用后关闭。跑。

委托方法

- (void)locationManager:(CLLocationManager *)manager 
     didDetermineState:(CLRegionState)state 
       forRegion:(CLRegion *)region 

永远不会被调用。

在iOS 7中是同一个应用程序。没有授权请求工作。

分享您的经验。

回答

0

后,我加入NSLocationAlwaysUsageDescription键值对到InfoPlist.strings它显示的对话框,并开始工作。

1

我从ios7迁移到ios8时遇到了同样的问题,我已经按照苹果文档的方式完成了解释。

检查什么苹果说,在这里:

APPLE DOC

从iOS版8,NSLocationWhenInUseUsageDescriptionInfo.plist文件NSLocationAlwaysUsageDescription键值也required.but您需要从用户请求权限您注册的位置之前,更新,或者致电[_locationManager requestWhenInUseAuthorization][_locationManager requestAlwaysAuthorization]根据您的要求选择上述任何一项。

请注意,这个信息将要去帮助通过了IOS 8

+0

requestAlwaysAuthorization的对话框不出现。在位置服务应用程序的设置。出现2个变体:从不,总是,但总是没有下面的描述。我期望有NSLocationAlwaysUsageDescription值。 – programmist 2014-09-30 07:54:16