mapbox-unity-sdk icon indicating copy to clipboard operation
mapbox-unity-sdk copied to clipboard

Mapbox not loading on Android first run

Open sasobogdanov opened this issue 4 years ago • 3 comments

I have an issue when launching app for the first time. I get location permission dialogue, but when i click "allow", mapbox doesn't load. On second launch of the app, everything works. I dug deep into code and found the problem - and workaround.

This is the part where unity is requesting permission. In this code only "AndroidPermission permission" is sent, but no Actions. https://github.com/mapbox/mapbox-unity-sdk/blob/b574bcfacdd3cb1833fdba0499b5ae55fee6e2b5/sdkproject/Assets/Mapbox/Unity/Location/DeviceLocationProvider.cs#L165 https://github.com/mapbox/mapbox-unity-sdk/blob/b574bcfacdd3cb1833fdba0499b5ae55fee6e2b5/sdkproject/Assets/Mapbox/Core/Plugins/Android/UniAndroidPermission/UniAndroidPermission.cs#L29

But even if you send OnAllow, OnDeny and OnDenyAndNeverAskAgain it doesn't get called in UniAndroidPermission.cs. That means: https://github.com/mapbox/mapbox-unity-sdk/blob/b574bcfacdd3cb1833fdba0499b5ae55fee6e2b5/sdkproject/Assets/Mapbox/Unity/Location/DeviceLocationProvider.cs#L167 We get stuck here, cause _gotPermissionRequestResponse is always false.

Simplest workaround is to replace while loop with: while (!_locationService.isEnabledByUser) { yield return _wait1sec; }

I don't know if this was intended or it's a bug.

sasobogdanov avatar Aug 06 '21 09:08 sasobogdanov

Hey @sasobogdanov ,

i already reported this some time ago: https://github.com/mapbox/mapbox-unity-sdk/issues/1760

you will have to trigger an permissionrequest yourself on first startup to avoid this bug in the DeviceLocationProvider class. @brnkhy will have a look at this for the next release

Markovicho avatar Aug 09 '21 07:08 Markovicho

Hey @sasobogdanov @Markovicho Thanks a lot for the report, I'm afraid I probably won't have a chance to look into this soon, wanted to openly share that with you :( do you at least have a temp solution? something like @Markovicho mentioned for example?

brnkhy avatar Oct 08 '21 12:10 brnkhy

@brnkhy It's been a while already since i discovered the issue but i think the error was pretty obvious. Will have a look again next week and maybe i can provide a proper hotfix for the DeviceLocationProvider class. For my current solution i sailed around asking for the permission via DeviceLocationProvider at all.

Markovicho avatar Oct 08 '21 20:10 Markovicho