Skip to content
Merged
Changes from 1 commit
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
29 changes: 15 additions & 14 deletions src/Essentials/src/Permissions/Permissions.ios.watchos.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,19 +199,7 @@ internal static PermissionStatus GetSensorPermissionStatus()

if (OperatingSystem.IsIOSVersionAtLeast(11, 0) || OperatingSystem.IsWatchOSVersionAtLeast(4, 0))
{
#pragma warning disable CA1416 // https://github.com/xamarin/xamarin-macios/issues/14619
switch (CMMotionActivityManager.AuthorizationStatus)
{
case CMAuthorizationStatus.Authorized:
return PermissionStatus.Granted;
case CMAuthorizationStatus.Denied:
return PermissionStatus.Denied;
case CMAuthorizationStatus.NotDetermined:
return PermissionStatus.Unknown;
case CMAuthorizationStatus.Restricted:
return PermissionStatus.Restricted;
}
#pragma warning restore CA1416
return ConvertAuthorizationStatus(CMMotionActivityManager.AuthorizationStatus);
}

return PermissionStatus.Unknown;
Expand All @@ -230,11 +218,24 @@ internal static async Task<PermissionStatus> RequestSensorPermission()
catch (Exception ex)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we catch a specific exception to Han die the fall back ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure and done

{
Debug.WriteLine("Unable to query activity manager: " + ex.Message);
return PermissionStatus.Denied;
// Fall back to checking the authorization status directly

Copilot AI Jul 20, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should explain why this fallback is necessary and what specific conditions trigger it. Consider mentioning iOS 16+ behavior or the specific exception types that are handled.

Suggested change
// Fall back to checking the authorization status directly
// Fall back to checking the authorization status directly because querying the activity manager
// may fail due to platform-specific limitations or exceptions. For example, on iOS 16+,
// certain permissions or system behaviors might prevent successful queries. This fallback
// ensures that we can still determine the permission status reliably.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you expand the comment adding more details?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return ConvertAuthorizationStatus(CMMotionActivityManager.AuthorizationStatus);
}

return PermissionStatus.Unknown;
}

private static PermissionStatus ConvertAuthorizationStatus(CMAuthorizationStatus status)
{
return status switch
{
CMAuthorizationStatus.Authorized => PermissionStatus.Granted,
CMAuthorizationStatus.Denied => PermissionStatus.Denied,
CMAuthorizationStatus.NotDetermined => PermissionStatus.Unknown,
CMAuthorizationStatus.Restricted => PermissionStatus.Restricted,
_ => PermissionStatus.Unknown,
};
}
}

public partial class LocationAlways : BasePlatformPermission
Expand Down