문제

내가 쓰는 응용 프로그램이 종료되면 현재 위치를 iPhone에 '디스크'에 저장해야합니다. 그런 다음 앱이 다시 시작되면이 정보를 복원하고 싶습니다. 그러나 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];

추신 : 손에 닿을 Mac이 없으므로 위 코드에 구문 오류가있을 수 있지만 아이디어를 얻을 수 있습니다. :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top