2014-09-29 23 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