2

locationServicesEnabled がプロパティからメソッドに変更されました。

これは非推奨です:

CLLocationManager *manager = [[CLLocationManager alloc] init];
if (manager.locationServicesEnabled == NO) {
     // ...
}

今私は使用する必要があります:

if (![CLLocationManager locationServicesEnabled]) {
    // ...
}

iOS 3 および iOS 4 デバイスをサポートしたい。iOS 3 デバイスでこれを確認し、非推奨の警告を取り除くにはどうすればよいですか?

4

3 に答える 3

5

プロパティ「locationServicesEnabled」は廃止されたばかりなので、引き続き使用できます (期間は未定)。状況を動的に処理するには、防御的なソリューションを提供する必要があります。上記のソリューションと同様に、次を使用しました。

BOOL locationAccessAllowed = NO ;
if( [CLLocationManager instancesRespondToSelector:@selector(locationServicesEnabled)] )
{
    // iOS 3.x and earlier
    locationAccessAllowed = locationManager.locationServicesEnabled ;
}
else if( [CLLocationManager respondsToSelector:@selector(locationServicesEnabled)] )
{
    // iOS 4.x
    locationAccessAllowed = [CLLocationManager locationServicesEnabled] ;
}

「instancesRespondToSelector」への呼び出しは、プロパティがまだ使用可能かどうかを確認し、クラス自体がメソッド呼び出しをサポートしていることを再確認します (静的メソッドであるため、YES と報告されます)。

ちょうど別のオプション。

于 2011-03-30T14:06:28.947 に答える
2

編集:

#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_1
  #if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_3_2
    if (![CLLocationManager locationServicesEnabled]) {
    // ...
    }
  #else
    CLLocationManager *manager = [[CLLocationManager alloc] init];
    if (manager.locationServicesEnabled == NO) {
       // ...
    }
  #endif
#else
CLLocationManager *manager = [[CLLocationManager alloc] init];
if (manager.locationServicesEnabled == NO) {
     // ...
}
#endif
于 2010-10-04T12:35:30.350 に答える
1

試す:

BOOL locationServicesEnabled;
CLLocationManager locationManager = [CLLocationManager new];
if( [locationManager respondsToSelector:@selector(locationServicesEnabled) ] )
{
    locationServicesEnabled = [locationManager locationServicesEnabled];
}
else
{
    locationServicesEnabled = locationManager.locationServicesEnabled;
}

修正/回避策として。

コンパイラ定義を使用すると、最小展開ターゲットを使用して古い OS バージョンのアプリケーションへのアクセスを許可するときに問題が発生します。

于 2010-10-22T00:59:46.493 に答える