Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] GeolocationEvent.UPDATE events doesn't dispatches if it listener added after PermissionEvent.PERMISSION_STATUS #2944

Open
itlancer opened this issue Nov 28, 2023 · 0 comments
Labels

Comments

@itlancer
Copy link

Problem Description

GeolocationEvent.UPDATE events doesn't dispatches if it listener added after PermissionEvent.PERMISSION_STATUS for iOS devices.
It could stuck development for a lot of developers. Also it could break complex UI and applications logic.

Tested with multiple AIR 50.2.x and latest AIR 50.2.4.1 with different AIR applications and different iOS devices with different iOS versions.
Same problem in all cases.
There is no such issue with Android.

Related issues:
#2943
#2830
#2822
#2809
#2022

Steps to Reproduce

  1. Launch application with code below with any iOS device (with enabled Location Services) and click anywhere on stage. It just need to grant location permission to application.
  2. Grant location permission to application for "always" usage.
  3. Close application and launch it again. It needed to workaround [iOS] Adding GeolocationEvent.UPDATE or StatusEvent.STATUS listener cause permission request dialog #2943 issue.
  4. Click anywhere on stage. Geolocation::setRequestedUpdateInterval() will be requested to start to get location information.

Application example with sources attached.
ios_geolocation_event_update_dispatch_bug.zip

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.sensors.Geolocation;
	import flash.events.GeolocationEvent;
	import flash.events.StatusEvent;
	import flash.events.MouseEvent;
	import flash.permissions.PermissionStatus;
	import flash.events.PermissionEvent;
	
	public class IOSGeolocationEventUpdateDispatchBug extends Sprite {
		private var geolocation:Geolocation;
		
		public function IOSGeolocationEventUpdateDispatchBug() {
			addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		private function init(e:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE, init);
			
			stage.addEventListener(MouseEvent.CLICK, click);
		}
		
		private function locationUpdate(e:GeolocationEvent):void {
			trace("locationUpdate", e.latitude, e.longitude, e.horizontalAccuracy, Geolocation.permissionStatus);
		}
		
		private function statusChanged(e:StatusEvent):void {
			trace("statusChanged", geolocation.muted);
			startGeo();
		}
		
		private function geolocationPermissionStatusChanged(e:PermissionEvent):void {
			trace("geolocationPermissionStatusChanged", e.status, Geolocation.permissionStatus);//"denied"
			
			if (Geolocation.permissionStatus == PermissionStatus.GRANTED){//Permission granted
				startGeo();
			}
		}
		
		public function click(e:MouseEvent):void {
			if (Geolocation.isSupported){
				geolocation = new Geolocation();
				
				geolocation.addEventListener(PermissionEvent.PERMISSION_STATUS, geolocationPermissionStatusChanged);
				
				//This block here to workaround https://github.com/airsdk/Adobe-Runtime-Support/issues/2943 issue
				if (Geolocation.permissionStatus == PermissionStatus.GRANTED){//Permission granted
					geolocation.addEventListener(GeolocationEvent.UPDATE, locationUpdate);
				}
				
				//Move adding PermissionEvent.PERMISSION_STATUS listener to here for workaround 
				
				if (Geolocation.permissionStatus == PermissionStatus.GRANTED){//Permission granted
					trace("permission granted");
					startGeo();
				} else {//Permission not granted
					trace("permission not granted: " + Geolocation.permissionStatus);
					geolocation.locationAlwaysUsePermission = true;
					geolocation.requestPermission();
				}
			} else {
				trace("Geolocation not supported");
			}
		}
		
		public function startGeo():void {
			trace("startGeo", geolocation.muted);
			geolocation.desiredAccuracy = Geolocation.LOCATION_ACCURACY_BEST;
			geolocation.pausesLocationUpdatesAutomatically = false;
			geolocation.addEventListener(GeolocationEvent.UPDATE, locationUpdate);
			geolocation.addEventListener(StatusEvent.STATUS, statusChanged);
			geolocation.setRequestedUpdateInterval(5000);
		}
	}
}

Actual Result:
In traces you will see:

permission granted
startGeo false

No GeolocationEvent.UPDATE events will be dispatched.

Expected Result:
In traces you will see:

permission granted
startGeo false
locationUpdate 0.704985 0.0635457 12.593000411987305

GeolocationEvent.UPDATE events will be dispatched.

Known Workarounds

Move:

geolocation.addEventListener(GeolocationEvent.UPDATE, locationUpdate);

before

geolocation.addEventListener(PermissionEvent.PERMISSION_STATUS, geolocationPermissionStatusChanged);
@itlancer itlancer added the Bug label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant