Mr Anoimus Mr Anoimus - 6 months ago 39
iOS Question

Getting Last Image of Album using Xamarin.IOS

I'm trying to get the last image from the album and share it on social media but whenever I tried searching for solutions, they are all either in Objective-C or Swift and I don't really understand either of the language.

I searched for solutions and got this which is in Objective-C:
Get last image from Photos.app?

and I have problems trying to convert the code myself from Objective-C to C# in Xamarin.IOS

The main problem that I got stuck with when converting is this line

fetchOptions.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];


I could not find sortDescriptorWithKey anywhere in Xamarin.IOS

Answer

It is in the constructor according to the documentation: https://developer.xamarin.com/api/type/Foundation.NSSortDescriptor/#Public_Constructors

so something like:

fetchOptions.SortDescriptors = new NSSortDescriptor[] {new NSSortDescriptor("creationDate", false)};
Comments