Tool for import XCode-Project

PhilippWegenerPhilippWegener USMember ✭✭

Hello,

i created an Cross-Platform App for Android and iOS.
My Problem now is, that I want to implement an XCode-Project.
How can I do that or is there a possibility to Import an Project like this ?

In the XCode-Project there is some Code which I want to use in my Xamarin.Forms Project.

Do you have any idea to do that ?

Best Answer

Answers

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @PhilippWegener

    I am not sure 100% what you are asking. You have a cross platform app for iOS and Android, that I get, and I assume you mean this is a Xamarin Cross-Platfrorm app, is that correct?

    Assuming that is correct you say that you now want to implement an Xcode project and then import it into your Xamarin Cross-Platform app. Is that correct? If so, my first question is why? Anything you can do in XCode you can do in Xamarin.iOS, IOW the entire iOS SDK is available in Xamarin. Every iOS, class, control, protocol etc. is available in Xamarin.iOS. So you could create your iOS specific library as a Xamarin.iOS library project rather than an XCode project and then use Dependency Injection (DependencyService) to access that Xam.iOS library from Xamarin.Forms core project.

    That said, you basically have two options to bring an XCode project into a Xamarin iOS project.

    1. Port the Obj-C / Swift code to C# code, which means basically re-writing the functionality in the XCode project in Xamarin.iOS, i.e. what I suggested above.
    2. Bind the Obj-C library, i.e. XCode project, (currently you cannot directly bind swift, but you can wrap your swift code in Obj-C wrappers and then bind to those Ob-C wrappers to C#) and then reference the binding from your Xam.iOS project. You will still need to use Dependency Injection (DependencyService) to access code from the bound iOS library in your Xam.Forms core project.

    Also moving this post to Xamarin.iOS as that is the more appropriate category for this thread.

  • PhilippWegenerPhilippWegener USMember ✭✭

    @JGoldberger

    Yes, you understand it Right.

    I have to implement this Code because I dont want to rewrite the Code and use the functions.

    I think your second answer is what i want to do.
    Because in the first answer, i have to rewrite the Obj-C/Swift Code, that is not what i want to do.
    I want to implement the Obj-C Project in my Cross-Platfrom Project. Is there a description how to implement a Project like this?

    In my Cross-Plattform App I know how to use DependencyService.

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @PhilippWegener

    I would start with these documents to get you going:
    https://docs.microsoft.com/en-us/xamarin/ios/platform/binding-objective-c/
    https://docs.microsoft.com/en-us/xamarin/cross-platform/macios/binding/

    Once you get your binding project built and working, you can reference it from your iOS app project and call into it from Forms core code using a DependencyService.

  • PhilippWegenerPhilippWegener USMember ✭✭

    @JGoldberger

    I have created an .a file and imported this file in my Xamarin.iOS Project.
    How can I call a method from the .a file?
    Is there a possibility to do it in Portable Project or in .iOS Project?

  • JGoldbergerJGoldberger USMember, Forum Administrator, Xamarin Team, University Xamurai

    @PhilippWegener said:

    I have created an .a file and imported this file in my Xamarin.iOS Project.
    How can I call a method from the .a file?
    Is there a possibility to do it in Portable Project or in .iOS Project?

    Did you read through the guides I sent you above? You have to create a Xamarin.iOS Binding Library project to add the .a file to. You also need to use Objective-Sharpie to bootstrap the C# wrappers that you will eventually use to call into your library. All of this is outlined in the links I sent.

    In the first link above, there is a link to a walk through that should take you step by step through the process.

    Please do note that creating bindings can be simple or difficult largely depending on the library that is being bound and how complex and/or well formed it is. But a good start is to go through that walk through using your own .a file instead of the one being used in the walkthrough.

    You will need to know what iOS frameworks and/or other native libraries that your static library (.a) depends on as well. Some familiarity with Objective-C is helpful as well.

  • PhilippWegenerPhilippWegener USMember ✭✭
    edited September 2018

    @JGoldberger
    Is it Right, that I can at least Import the .a file or Xamarin.iOS Binding Library in my Xamarin.Forms Portable Project and use the Methods?

Sign In or Register to comment.