mono / Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
MIT License
758 stars 95 forks source link

[ObjC] Embedding a library using PHAsset etc causes dupes for Mac #543

Open equinox2k opened 6 years ago

equinox2k commented 6 years ago

Note: using latest beta of Visual Studio for Mac

Example segment of header created...

@class PHObject;
@class PHAsset;
@class PHFetchOptions;
@class PHFetchResult;
@class PHImageManager;
@class PHImageRequestOptions;

@interface PHObject : NSObject {
}
    -(NSObject *) copyWithZone:(id)p0;
@end

@interface PHAsset : PHObject {
}
@end

@interface PHFetchOptions : NSObject {
}
    -(NSObject *) copyWithZone:(id)p0;
    -(id) init;
@end

@interface PHFetchResult : NSObject {
}
    -(NSObject *) copyWithZone:(id)p0;
    -(NSObject *) objectAtIndex:(NSInteger)p0;
@end

@interface PHImageManager : NSObject {
}
    -(int) requestImageForAsset:(id)p0 targetSize:(CGSize)p1 contentMode:(NSInteger)p2 options:(id)p3 resultHandler:(id)p4;
@end

@interface PHImageRequestOptions : NSObject {
}
    -(NSObject *) copyWithZone:(id)p0;
    -(id) init;
@end

From a method like...

        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            InfoTextField.StringValue = ProjectAssets.SharedInstance().GetAssets().Count().ToString();

            var identifiers = ProjectAssets.SharedInstance().GetAssets();
            if (identifiers.Length > 0)
            {
                var options = new PHFetchOptions();
                var fetchResult = PHAsset.FetchAssetsUsingLocalIdentifiers(identifiers, options);
                PHAsset asset = (PHAsset)fetchResult.ObjectAt(0);
                PHImageRequestOptions options2 = new PHImageRequestOptions();
                PHImageManager.DefaultManager.RequestImageForAsset(asset, new CoreGraphics.CGSize(500, 500), PHImageContentMode.AspectFill, options2, (NSImage result, NSDictionary info) =>
                {
                    TestImageView.Image = result;
                });
            }
        }

Xcode reports duplicate definitions of each of the

PHObject; PHAsset; PHFetchOptions; PHFetchResult; PHImageManager; PHImageRequestOptions;

equinox2k commented 6 years ago

@tritao is there any way I can update Embeddinator to not do above?

chamons commented 6 years ago

In your c# project, are you defining classes called PHObject?

Without seeing more, it is difficult to understand what is going on.

Could you attach a project showing the issue?

equinox2k commented 6 years ago

@chamons I've created a Xamarin test solution "PNI.Mobile.sln" that creates and copies an embedded framework to an Xcode project. "PNIPhotoProjectDemo.xcodeproj"

if you run both in sequence you should see problem mentioned above...

https://www.dropbox.com/s/hvkn39vscnpkd4u/ProblemExample.zip?dl=0

As to your question, the .Net library uses "using Photos;" with appropriate code and the Xcode project also uses "#import <Photos/Photos.h>", I am not myself defining any class names like PHObject...

the problem lies in fact that the header created in framework contains the duplicate interfaces...

e.g. @interface PHObject : NSObject { } -(NSObject *) copyWithZone:(id)p0; @end

which conflicts with the "#import <Photos/Photos.h>" used

equinox2k commented 6 years ago

@chamons have you been able to look into why this happens? For now as a work around I’m using sed to remove chunks of code from header.

chamons commented 6 years ago

@equinox2k - No, I have no yet. It's currently bucketed for after a potential .4 release.

I'm glad you have a work around right currently.