2014-10-10 91 views
2

我正在使用iBeacons,但遇到了一個小問題。CLLocationManager委託未調用

第一次使用時,用戶需要賦予權限,然後我們下面被稱爲:

_locationManager = [[CLLocationManager alloc] init]; 
_locationManager.delegate = self; 
[_locationManager requestAlwaysAuthorization]; 

不過,我預計將稱爲以下的委託方法:

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { 
    NSLog(@"Auth status changed: %i", status); 
    if(status > 3){ 
     // Check if we have to start monitoring beacons 
     NSLog(@"Do we need to initialise after auth given?"); 
     //[self initialiseLocations]; 
    } 
} 

我運行iOS 8.0.2,所以不知道這是否是一個錯誤

+0

你是否設置了對locationManager的強引用,類似'@property(nonatomic,strong)CLLocationManager * locationManager;'? – 2014-10-10 18:36:48

+0

不,但在全球範圍內在.h文件中聲明它。包含的類很強大,在appDelegate中定義。所有其他回調工作正常,只是這一個。 – 2014-10-10 19:16:36

回答

0

This answer可能會幫助...它至少解決了它。此外,this website對於這個問題也是一個很好的演練。

看起來您正在調用requestAlwaysAuthorization,但您是否在任何地方撥打startUpdatingLocation?另外,請仔細檢查在您的Info.plist中您是否已添加適當的密鑰和字符串值(因爲您使用的是requestAlwaysAuthorization,所以爲NSLocationAlwaysUsageDescription)。

+0

我有這些設置,而且它工作正常,否則(我使用它爲iBeacons,所以不需要啓動startUpdatingLocation,因爲這是GPS)。這就是爲什麼我需要回調,所以我可以發起跟蹤信標的請求。 – 2014-10-10 18:53:03

+0

哦,我從來沒有使用iBeacons,所以我不完全確定然後...我做了一個快速搜索,然後發現[本教程](http://ibeaconmodules.us/blogs/news/14279747-tutorial-ibeacon -app-development-with-corelocation-on-apple-ios-7-8)過度使用它們,並聲明他們對它進行了編輯以便與iOS 8一起使用,所以也許它會有所幫助? – 2014-10-10 19:41:47