UIImagePickerControllerDelegate in foreign code

How can I set a class to be a UIImagePickerControllerDelegate in foreign code? I know I can use IUIImagePickerControllerDelegate with the old bindings.

The recommended way to do that is to implement a class that conforms to the protocol in Objective-C. If you use the file types ObjCSource and ObjCHeader you can use the same UXL macros that you can use in foreign code, meaning that there are several ways to call back to Uno from the class. Depending on your requirements, you can:

  • Call static Uno methods directly using macros.
  • Make your class hold on to an Uno object (id<UnoObject>) and call methods on it using macros.
  • Make your class hold one or several Objective-C blocks that it calls when certain events are triggered. Since Uno delegates are automatically converted to blocks in Objective-C, it’s very easy to pass them to your class at construction-time.

Great! First part worked. I’m trying to call static Uno methods now, but having some problems:

/Users/bolav/Fuse/fuse-gallery/build/iOS/Debug/src/TakePictureTask.m /Users/bolav/Fuse/fuse-gallery/build/iOS/Debug/src/TakePictureTask.m:73:8: Expected expression /Users/bolav/Fuse/fuse-gallery/build/iOS/Debug/src/TakePictureTask.m:73:15: Expected identifier

From this code:

@{iOSGalleryImpl.Cancelled():Call()};

Which generated this:

& -> void { ::uAutoReleasePool __autoReleasePool; ::g::iOSGalleryImpl::Cancelled(); }();

And do you need to add an import/include in the .m file?

Also do you have directives to protect a method from being stripped?

Your file has to be an mm file (see the docs). To get the include directives in that file right you can use e.g. @{iOSGalleryImpl:IncludeDirective}.

Processed external files are processed after stripping is completed, so currently you will have to use the Require("Entity", "...") attribute (or UXL element) or make sure that the entity is used elsewhere to stop it from being stripped.

Great success!

Gallery example now working.

https://github.com/bolav/fuse-gallery