Here I present a video of the results of some work I’ve been doing with the iOS Photos Framework with Delphi
A while ago I posted about using the ALAssetsLibrary in iOS. In that article, I briefly mentioned the Photos Framework, which is now the preferred method of managing media stored on iOS devices (i.e. ALAssetsLibrary is deprecated, since iOS 8.0, not 9.0, as I had previously stated)
Since the headers for the Photos Framework are not supplied with Delphi (at least at time of writing), in order to use the framework it would normally be a daunting task of manually converting the .h files into Delphi. When Delphi 10.1 Berlin was released, it shipped with a tool called SDKTransform, which automates (for the most part, and not always perfectly) the conversion of the SDK header files. The task is made even easier using the excellent SDKTransform Assistant, written by Hosakawa Jun. A bit of tweaking later, and I had a unit with all the definitions I needed for the iOS Photos Framework.
However, it is one thing to have an API; it’s totally another to do something useful with it. I left what I had done so far, for a while, then revisited it later when I felt I needed to progress the work. I waded through the documentation, and through some examples I googled for.
Sadly, I soon came up against a major roadblock. There are two methods used to retrieve the actual images, which are part of the PHImageManager class: requestImageForAsset and requestImageDataForAsset. Both methods require what is called a “block” handler to be passed, so that it is called once the image data is ready. Using the Delphi types of methods (regular procedure and object method) for “block” handlers does not work. A lot more googling and experimentation later, and I had eventually resolved that it wasn’t going to be possible to achieve; at least using Delphi code.
The answer was to write a library in ObjectiveC, which contains a class that acts as kind of a proxy; doing the work of the methods in question, and passing the “block” handler from within it. I defined a delegate protocol in the library that I could implement in my Delphi code, so that the result could be passed on once the “block” handler was called.
Since I was able to make that work, I set about creating a demo that acts somewhat like the photo selection dialog in Facebook on iOS (this image is of that dialog, not of my work):
The results so far of my work are in the video which follows. Note that this is preliminary work, so it has a few quirks that need to be ironed out.