Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Prefix user defaults in iosapp #2286

Merged
merged 1 commit into from
Sep 16, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions ios/app/MBXViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ + (void)initialize
if (self == [MBXViewController class])
{
[[NSUserDefaults standardUserDefaults] registerDefaults:@{
@"userTrackingMode": @(MGLUserTrackingModeNone),
@"showsUserLocation": @NO,
@"debug": @NO,
@"MBXUserTrackingMode": @(MGLUserTrackingModeNone),
@"MBXShowsUserLocation": @NO,
@"MBXDebug": @NO,
}];
}
}
Expand Down Expand Up @@ -91,10 +91,10 @@ - (void)saveState:(__unused NSNotification *)notification
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *archivedCamera = [NSKeyedArchiver archivedDataWithRootObject:self.mapView.camera];
[defaults setObject:archivedCamera forKey:@"camera"];
[defaults setInteger:self.mapView.userTrackingMode forKey:@"userTrackingMode"];
[defaults setBool:self.mapView.showsUserLocation forKey:@"showsUserLocation"];
[defaults setBool:self.mapView.debugActive forKey:@"debug"];
[defaults setObject:archivedCamera forKey:@"MBXCamera"];
[defaults setInteger:self.mapView.userTrackingMode forKey:@"MBXUserTrackingMode"];
[defaults setBool:self.mapView.showsUserLocation forKey:@"MBXShowsUserLocation"];
[defaults setBool:self.mapView.debugActive forKey:@"MBXDebug"];
[defaults synchronize];
}
}
Expand All @@ -103,21 +103,21 @@ - (void)restoreState:(__unused NSNotification *)notification
{
if (self.mapView) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSData *archivedCamera = [defaults objectForKey:@"camera"];
NSData *archivedCamera = [defaults objectForKey:@"MBXCamera"];
MGLMapCamera *camera = archivedCamera ? [NSKeyedUnarchiver unarchiveObjectWithData:archivedCamera] : nil;
if (camera)
{
self.mapView.camera = camera;
}
NSInteger uncheckedTrackingMode = [defaults integerForKey:@"userTrackingMode"];
NSInteger uncheckedTrackingMode = [defaults integerForKey:@"MBXUserTrackingMode"];
if (uncheckedTrackingMode >= 0 &&
(NSUInteger)uncheckedTrackingMode >= MGLUserTrackingModeNone &&
(NSUInteger)uncheckedTrackingMode <= MGLUserTrackingModeFollowWithCourse)
{
self.mapView.userTrackingMode = (MGLUserTrackingMode)uncheckedTrackingMode;
}
self.mapView.showsUserLocation = [defaults boolForKey:@"showsUserLocation"];
self.mapView.debugActive = [defaults boolForKey:@"debug"];
self.mapView.showsUserLocation = [defaults boolForKey:@"MBXShowsUserLocation"];
self.mapView.debugActive = [defaults boolForKey:@"MBXDebug"];
}
}

Expand Down