その後のその後

iOSエンジニア 堤 修一のブログ github.com/shu223

位置情報のOn/Off、許可/不許可を確認する

Appleのドキュメントを見ながら、CLLocationManager の Boolean を返す系のメソッドがそれぞれどういうことを意味しているのか調べてみました。
ただこの調査、iOS5リリース以前(2011年7月)に行ったものなので、情報が古いところがあるかもしれません。

locationServicesEnabled

The user can enable or disable location services from the Settings application by toggling the Location Services switch in General.
You should check the return value of this method before starting location updates to determine whether the user has location services enabled for the current device. If this method returns NO and you start location updates anyway, the Core Location framework prompts the user with a confirmation panel asking whether location services should be reenabled.

位置情報のon/off設定
Noが返ってきたときにlocation updates を start しようとすると、位置情報を有効にする旨のプロンプトが表示される

regionMonitoringAvailable

Support for region monitoring may not be available on all devices and models. You should check the value of this property before attempting to set up any regions or initiate region monitoring.
Even if region monitoring support is present on a device, it may still be unavailable because the user disabled it for the current application or for all applications.

region monitoringがデバイス的に利用可能かどうかを返してくれる。(つまりユーザーが設定でon/offにしてるかどうかではなく)

regionMonitoringEnabled

The user can enable or disable location services (including region monitoring) altogether from the Settings application by toggling the switch in Settings > General > Location Services.
You should check the return value of this method before starting region monitoring updates to determine if the user currently allows location services to be used at all. If this method returns NO and you start region monitoring updates anyway, the Core Location framework prompts the user with a confirmation panel asking whether location services should be reenabled.
This method does not check to see if region monitoring capabilities are actually supported by the device. Therefore, you should also check the return value of the regionMonitoringAvailable class method before attempting to start region monitoring services.

region monitoringを含む位置情報サービスのon/off設定
Noが返ってきたときにlocation updates を start しようとすると、位置情報を有効にする旨のプロンプトが表示される

significantLocationChangeMonitoringAvailable

This method indicates whether the device is able to report updates based on significant location changes only. (This primarily involves detecting changes in the cell tower currently associated with the device.)

シグニフィカント位置モニタリングがデバイス的に利用可能かどうかを返す


試してみました

「locationServicesEnabledでNoが返ってきたときにそのままstartUpdatingLocationすると位置情報を設定しにいくか聞くダイアログが出てくる」を試してみましたが、最初の一度しか出てきませんでした。位置情報が必須のアプリの場合、これだと中途半端かもしれません。
下記のような感じで、locationManager:didFailWithError:でエラーの原因を切り分けることはできました。

- (void) locationManager:(CLLocationManager *)manager
		didFailWithError:(NSError *)error {

	NSLog(@"error:%@", error);
    
    if([error code] == kCLErrorDenied) {
        // 設定で位置情報がoffになっている場合
        if (![CLLocationManager locationServicesEnabled]) {
            [KOFCommon showAlertWithTitle:@"エラー" msg:@"位置情報設定をOnにしてください" delegate:nil tag:0];
        }
        // 位置情報の取得を「許可しない」を選択した場合
        else {
            [KOFCommon showAlertWithTitle:@"エラー" msg:@"位置情報の利用を許可してください" delegate:nil tag:0];
        }
    }
}