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

supportedMaxPhotoDimensions not bound (highResolutionStillImageDimensions is deprecated since iOS 8) #16954

Closed
softlion opened this issue Dec 3, 2022 · 1 comment · Fixed by #17310
Assignees
Milestone

Comments

@softlion
Copy link

softlion commented Dec 3, 2022

Steps to Reproduce

  1. Create a xamarin iOS project
  2. Paste the following code
using AVFoundation;
...

using var device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video);
var maxSize = device.ActiveFormat.HighResolutionStillImageDimensions;

HighResolutionStillImageDimensions is deprecated since iOS 8:
https://developer.apple.com/documentation/avfoundation/avcapturedevice/format/1624620-highresolutionstillimagedimensio

Its replacement is not bound in Xamarin:
https://developer.apple.com/documentation/avfoundation/avcapturedeviceformat/3950866-supportedmaxphotodimensions

I've searched this repo and found a "not bound" annotation in some kind of log files for supportedmaxphotodimensions.

Is there a way to bind it manually ?

@property(nonatomic, readonly) [NSArray](https://developer.apple.com/documentation/foundation/nsarray)<[NSValue](https://developer.apple.com/documentation/foundation/nsvalue) *> *supportedMaxPhotoDimensions;

Expected Behavior

the property supportedmaxphotodimensions should exist

Actual Behavior

It does not.

Environment

Xamarin iOS SDK stable

@rolfbjarne rolfbjarne self-assigned this Jan 19, 2023
@rolfbjarne rolfbjarne added this to the Future milestone Jan 19, 2023
@rolfbjarne
Copy link
Member

It looks like something like this could be a workaround:

internal const string LIBOBJC_DYLIB = "/usr/lib/libobjc.dylib";
[DllImport(LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")]
public extern static CMVideoDimensions CMVideoDimensions_objc_msgSend(IntPtr receiver, IntPtr selector);

[DllImport(LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")]
public extern static IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector);

public void ShowDimensions ()
{
	AVCaptureDevice.RequestAccessForMediaType(AVAuthorizationMediaType.Video, (v) =>
	{
		using var device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video);
		var format = device.ActiveFormat;
		var maxSize = format.HighResolutionStillImageDimensions;
		var arrayHandle = IntPtr_objc_msgSend(format.Handle, Selector.GetHandle("supportedMaxPhotoDimensions"));
		var array = Runtime.GetNSObject<NSArray>(arrayHandle);
		var nsvalues = array.ToArray<NSValue>();
		for (var i = 0; i < nsvalues.Length; i++)
		{
			var value = nsvalues[i];
			var dimension = CMVideoDimensions_objc_msgSend(value.Handle, Selector.GetHandle("CMVideoDimensionsValue"));
			Console.WriteLine($"Dimension #{i + 1}: Height={dimension.Height} Width: {dimension.Width}");
		}
	});
}

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jan 19, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants