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

Fix iosapp location ask - #2265

Merged
incanus merged 2 commits into
masterfrom
fix-iosapp-location-ask
Sep 7, 2015
Merged

incanus merged 2 commits into
masterfrom
fix-iosapp-location-ask

Conversation

@friedbunny

Copy link
Copy Markdown
Contributor

The iosapp demo app was asking for location permission via showsUserLocation = YES in viewDidLoad, then immediately having restoreState: set showsUserLocation = NO because that's what the default is.

This PR lets restoreState: do the setting of showsUserLocation and then only asks for permissions if the value is NO — after a delay to allow the map to load.

Fixes #1930.

/cc @1ec5 @incanus

@friedbunny friedbunny added bug iOS Mapbox Maps SDK for iOS labels Sep 4, 2015
@friedbunny friedbunny added this to the ios-v2.1.0 milestone Sep 4, 2015
@friedbunny

Copy link
Copy Markdown
Contributor Author

RE: @incanus in #1930 (comment)

I'm not generally into timers, but in the interest of simplicity, maybe just set showsUserLocation = YES a second after viewDidAppear:?

Went with two seconds at the end of viewDidLoad:, only on the first launch (or any launch after that doesn't have permission, I suppose). Whatcha' think?

@incanus

incanus commented Sep 4, 2015

Copy link
Copy Markdown
Contributor

I think this is fine. However if we save & restore userTrackingMode, this will implicitly show the user dot, right?

@1ec5

1ec5 commented Sep 4, 2015

Copy link
Copy Markdown
Contributor

However if we save & restore userTrackingMode, this will implicitly show the user dot, right?

The user might want to see the user dot without following it.

@incanus

incanus commented Sep 4, 2015

Copy link
Copy Markdown
Contributor

My point is that restoring tracking mode at launch will have the same affect as restoring showing the user dot — still prompt the user without delay when restoring state.

@friedbunny

Copy link
Copy Markdown
Contributor Author

If the saved user tracking mode was none and we didn't explicitly set mapView.showsUserLocation, the dot would not appear initially. I kept settings->showsUserLocation because it's useful in determining if location is authorized.

The delayed mapView.showsUserLocation should only be triggered on the first launch, because we turn .showsUserLocation on when location permissions are given and it is never turned off at any point after. (Disabling user tracking when the dot is shown doesn't disable .showsUserLocation.)

@incanus
incanus merged commit 584c36f into master Sep 7, 2015
@incanus incanus removed the ready label Sep 7, 2015
@incanus
incanus deleted the fix-iosapp-location-ask branch September 7, 2015 16:20
@maciekish

Copy link
Copy Markdown
Contributor

@friedbunny

Copy link
Copy Markdown
Contributor Author

This was broken subsequently in 0a172a2#diff-33b34b5f099a16158c8462652a0c3688 when we moved directly to using NSUserDefaults instead of an intermediary. I'll get a fix in.

@maciekish

Copy link
Copy Markdown
Contributor

I think you may want to prefix your defaults or use initWithSuiteName: or something to avid clashes with defaults names.

friedbunny added a commit that referenced this pull request Sep 8, 2015
Previously in #2265 we would ask for location permission at app startup if `!settings->showsUserLocation`. #2193 0a172a2 changed the way we used `NSUserDefaults` and mostly removed the `settings` object, which broke #2265.

Rather than fix our pestering location permissions ask at startup, this commit now only asks for location permissions when the user hits the locate-me button.

Once a user grants permission, the user dot appears because a `userTrackingMode` is set, `showsUserLocation` is permanently set to `YES` in `NSUserDefaults` and is restored at launch.
@friedbunny

Copy link
Copy Markdown
Contributor Author

I think you may want to prefix your defaults or use initWithSuiteName: or something to avid clashes with defaults names.

Sandboxing means that we only have to contend with certain Apple NSUserDefaults (which tend to be namespaced themselves). A real app may need to worry about this, but our demo app likely does not.

friedbunny added a commit that referenced this pull request Sep 11, 2015
Previously in #2265 we would ask for location permission at app startup if `!settings->showsUserLocation`. #2193 0a172a2 changed the way we used `NSUserDefaults` and mostly removed the `settings` object, which broke #2265.

Rather than fix our pestering location permissions ask at startup, this commit now only asks for location permissions when the user hits the locate-me button.

Once a user grants permission, the user dot appears because a `userTrackingMode` is set, `showsUserLocation` is permanently set to `YES` in `NSUserDefaults` and is restored at launch.
AndwareSsj pushed a commit to AndwareSsj/mapbox-gl-native that referenced this pull request Nov 6, 2015
Previously in mapbox#2265 we would ask for location permission at app startup if `!settings->showsUserLocation`. mapbox#2193 0a172a2 changed the way we used `NSUserDefaults` and mostly removed the `settings` object, which broke mapbox#2265.

Rather than fix our pestering location permissions ask at startup, this commit now only asks for location permissions when the user hits the locate-me button.

Once a user grants permission, the user dot appears because a `userTrackingMode` is set, `showsUserLocation` is permanently set to `YES` in `NSUserDefaults` and is restored at launch.
AndwareSsj pushed a commit to AndwareSsj/mapbox-gl-native that referenced this pull request Nov 6, 2015
Previously in mapbox#2265 we would ask for location permission at app startup if `!settings->showsUserLocation`. mapbox#2193 0a172a2 changed the way we used `NSUserDefaults` and mostly removed the `settings` object, which broke mapbox#2265.

Rather than fix our pestering location permissions ask at startup, this commit now only asks for location permissions when the user hits the locate-me button.

Once a user grants permission, the user dot appears because a `userTrackingMode` is set, `showsUserLocation` is permanently set to `YES` in `NSUserDefaults` and is restored at launch.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug iOS Mapbox Maps SDK for iOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants