Binding Fusuma woes

CheesebaronCheesebaron DKInsider, University mod

Amazingly I've never bound anything for iOS before. So I found this nice cocoapod that I wanted to try my luck with.

What I have done until now is the following:

sharpie pod init ios Fusuma

sharpie pod bind Fusuma

This has generated the following files for me:

Fusuma.framework
Fusuma_ApiDefinition.cs

I then created a new iOS binding project in Xamarin.Studio and added Fusuma.framework as native reference and copied over the contents of Fusuma_ApiDefinition.cs over in ApiDefinition.cs in the default project structure.

So far so good. The sharpie binding did tell me there were two issues with the ApiDefinition:

[Static]
[Verify (ConstantsInterfaceAssociation)]
partial interface Constants
{
    // extern double FusumaVersionNumber;
    [Field ("FusumaVersionNumber", "__Internal")]
    double FusumaVersionNumber { get; }

    // extern const unsigned char [] FusumaVersionString;
    [Field ("FusumaVersionString", "__Internal")]
    byte [] FusumaVersionString { get; }
}

and later in the file:

[Export ("prefersStatusBarHidden")]
[Verify (MethodToProperty)]
bool PrefersStatusBarHidden { get; }

Removing the Verify attributes lets me build the project. However, the build fails. First error is that the FusumaVersionString has an unsupported type for fields byte[]. I am not super interested in the FusumaVersionString so I just removed that.

Now I get 3 new errors:

/Users/tomasz/Projects/Fusuma/Fusuma/obj/Debug/ios/Fusuma/FusumaViewController_Fusuma_Swift_140.g.cs(38,37): error CS0714: Static class `Fusuma.FusumaViewController_Fusuma_Swift_140' cannot implement interfaces
/Users/tomasz/Projects/Fusuma/Fusuma/obj/Debug/ios/Fusuma/FusumaViewController.g.cs(109,10): error CS0111: A member `Fusuma.FusumaViewController.FusumaViewController(Foundation.NSCoder)' is already defined. Rename this member or use different parameter types
/Users/tomasz/Projects/Fusuma/Fusuma/obj/Debug/ios/Fusuma/FusumaViewController.g.cs(178,10): error CS0246: The type or namespace name `FusumaDelegate' could not be found. Are you missing an assembly reference?

Here is the ApiDefinitions.cs file I have currently:

using System;

using UIKit;
using Foundation;
using ObjCRuntime;
using CoreGraphics;

namespace Fusuma
{

    [Static]
    partial interface Constants
    {
        // extern double FusumaVersionNumber;
        [Field ("FusumaVersionNumber", "__Internal")]
        double FusumaVersionNumber { get; }
    }

    // @protocol FSAlbumViewDelegate
    [Protocol, Model]
    interface FSAlbumViewDelegate
    {
        // @required -(void)albumViewCameraRollUnauthorized;
        [Abstract]
        [Export ("albumViewCameraRollUnauthorized")]
        void AlbumViewCameraRollUnauthorized ();
    }

    // @protocol FusumaDelegate
    [Protocol, Model]
    interface FusumaDelegate
    {
        // @required -(void)fusumaImageSelected:(UIImage * _Nonnull)image;
        [Abstract]
        [Export ("fusumaImageSelected:")]
        void FusumaImageSelected (UIImage image);

        // @optional -(void)fusumaDismissedWithImage:(UIImage * _Nonnull)image;
        [Export ("fusumaDismissedWithImage:")]
        void FusumaDismissedWithImage (UIImage image);

        // @required -(void)fusumaVideoCompletedWithFileURL:(NSURL * _Nonnull)fileURL;
        [Abstract]
        [Export ("fusumaVideoCompletedWithFileURL:")]
        void FusumaVideoCompletedWithFileURL (NSUrl fileURL);

        // @required -(void)fusumaCameraRollUnauthorized;
        [Abstract]
        [Export ("fusumaCameraRollUnauthorized")]
        void FusumaCameraRollUnauthorized ();

        // @optional -(void)fusumaClosed;
        [Export ("fusumaClosed")]
        void FusumaClosed ();
    }

    // @interface FusumaViewController : UIViewController
    [BaseType (typeof (UIViewController))]
    interface FusumaViewController
    {
        // @property (nonatomic) BOOL hasVideo;
        [Export ("hasVideo")]
        bool HasVideo { get; set; }

        [Wrap ("WeakDelegate")]
        [NullAllowed]
        FusumaDelegate Delegate { get; set; }

        // @property (nonatomic, weak) id<FusumaDelegate> _Nullable delegate;
        [NullAllowed, Export ("delegate", ArgumentSemantic.Weak)]
        NSObject WeakDelegate { get; set; }

        // -(void)loadView;
        [Export ("loadView")]
        void LoadView ();

        // -(void)viewDidLoad;
        [Export ("viewDidLoad")]
        void ViewDidLoad ();

        // -(void)viewWillAppear:(BOOL)animated;
        [Export ("viewWillAppear:")]
        void ViewWillAppear (bool animated);

        // -(void)viewDidAppear:(BOOL)animated;
        [Export ("viewDidAppear:")]
        void ViewDidAppear (bool animated);

        // -(void)viewWillDisappear:(BOOL)animated;
        [Export ("viewWillDisappear:")]
        void ViewWillDisappear (bool animated);

        // -(BOOL)prefersStatusBarHidden;
        [Export ("prefersStatusBarHidden")]
        bool PrefersStatusBarHidden { get; }

        // -(instancetype _Nonnull)initWithNibName:(NSString * _Nullable)nibNameOrNil bundle:(NSBundle * _Nullable)nibBundleOrNil __attribute__((objc_designated_initializer));
        [Export ("initWithNibName:bundle:")]
        [DesignatedInitializer]
        IntPtr Constructor ([NullAllowed] string nibNameOrNil, [NullAllowed] NSBundle nibBundleOrNil);

        // -(instancetype _Nullable)initWithCoder:(NSCoder * _Nonnull)aDecoder __attribute__((objc_designated_initializer));
        [Export ("initWithCoder:")]
        [DesignatedInitializer]
        IntPtr Constructor (NSCoder aDecoder);
    }

    // @interface Fusuma_Swift_140 (FusumaViewController) <FSAlbumViewDelegate>
    [Category]
    [BaseType (typeof (FusumaViewController))]
    interface FusumaViewController_Fusuma_Swift_140 : FSAlbumViewDelegate
    {
        // -(void)albumViewCameraRollUnauthorized;
        [Export ("albumViewCameraRollUnauthorized")]
        void AlbumViewCameraRollUnauthorized ();
    }

    // @interface Fusuma_Swift_145 (FusumaViewController)
    [Category]
    [BaseType (typeof (FusumaViewController))]
    interface FusumaViewController_Fusuma_Swift_145
    {
    }

    // @interface Fusuma_Swift_149 (NSIndexSet)
    [Category]
    [BaseType (typeof (NSIndexSet))]
    interface NSIndexSet_Fusuma_Swift_149
    {
    }

    // @interface Fusuma_Swift_153 (UICollectionView)
    [Category]
    [BaseType (typeof (UICollectionView))]
    interface UICollectionView_Fusuma_Swift_153
    {
    }

    // @interface Fusuma_Swift_157 (UIColor)
    [Category]
    [BaseType (typeof (UIColor))]
    interface UIColor_Fusuma_Swift_157
    {
    }

    // @interface Fusuma_Swift_161 (UIView)
    [Category]
    [BaseType (typeof (UIView))]
    interface UIView_Fusuma_Swift_161
    {
    }

}

Could someone help me bind this?

Answers

  • CheesebaronCheesebaron DKInsider, University mod

    I got it to build now. However, I think some adjustments need to be made.

    So I did the following to get it to build.

    I removed

    // -(instancetype _Nullable)initWithCoder:(NSCoder * _Nonnull)aDecoder __attribute__((objc_designated_initializer));
            [Export ("initWithCoder:")]
            [DesignatedInitializer]
            IntPtr Constructor (NSCoder aDecoder);
    

    I removed interface FusumaViewController_Fusuma_Swift_140 : FSAlbumViewDelegate and inherited FusumaViewController from FSAlbumViewDelegate and moved the AlbumViewCameraRollUnauthorized method up there too.

    I removed all the empty interfaces at the bottom too, builds with or without.

    My problem now is that the two Delegates, FusumaDelegate and FSAlbumViewDelegate are classes and not interfaces, so A UIViewController cannot implement either. How do I get around that?

  • kwlkwl USInsider, Developer Group Leader ✭✭

    @Cheesebaron Have you had a look at [BaseType]?

  • CheesebaronCheesebaron DKInsider, University mod

    Think I am going to do a Swift -> C# translation instead, because I need to customize some things anyways.

Sign In or Register to comment.