質問

書き込み中のアプリケーションが終了した場合、iPhoneの「ディスク」に現在の場所を保存する必要があります。その後、アプリが再び起動したら、この情報を復元します。ただし、CLLocation座標プロパティは読み取り専用です。

プログラムの呼び出し間でこの情報を保存する(およびCLLocationオブジェクトに再適用する)にはどうすればよいですか?

役に立ちましたか?

解決

NSDefaultsを使用して保存できます。次のようなもの

#define kLocationLat @"LOCATION_LAT"
#define kLocationLng @"LOCATION_LNG"

// Store the location
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.lat forKey:kLocationLat];
[[NSUserDefaults standardUserDefaults] setDouble:location.coordinate.lng forKey:kLocationLng];

// Retrieve the location
CLLocationDegrees lat = [[NSUserDefaults standardUserDefaults] doubleForKey:kLocationLat];
CLLocationDegrees lng = [[NSUserDefaults standardUserDefaults] doubleForKey:kLocationLng];
CLLocation *location = [[CLLocation alloc] initWithLatitude:lat longitude:lng];

サム

PS手元にMacがないので、上記のコードに構文エラーがあるかもしれませんが、あなたはそのアイデアを得ます:)

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top