Forum Xamarin.Forms

Issue with Creating Card Connect SDK Xamarin binding Library for iOS

AnandVKAnandVK USMember ✭✭

I created a Xamarin Binding Library project to map the card connect sdk for ios and was successful in it. But when I try to create a sample project to test the function its giving me the following error.

Could not create an native instance of the type 'CardConnect.CCCPaymentRequest': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.

You can find the Objective C & Swift sample and documentation in the link below https://developer.cardconnect.com/mobile-sdks#iOS

Also I am trying to bind an Objective C framework library

Best Answer

  • AnandVKAnandVK US ✭✭
    Accepted Answer

    Adding “Additional mtouch arguments” = “--optimize=-remove-dynamic-registrar” to the sample solves the issue.

    The complete solution is updated in Github

Answers

  • ColeXColeX Member, Xamarin Team Xamurai
    edited January 2019

    Add the LinkWith attribute in Linker file to declare supported architectures and referencing frameworks.

    Such as

    [assembly: LinkWith ("libSVGKit-iOS.1.2.0.a", LinkTarget.ArmV7 | LinkTarget.Simulator | LinkTarget.Arm64 | LinkTarget.Simulator64, SmartLink = true, Frameworks="QuartzCore CoreText CoreGraphics CoreImage UIKit", LinkerFlags="-lxml2 -ObjC", ForceLoad = true)]

    Check https://stackoverflow.com/a/27974921/8187800

  • AnandVKAnandVK USMember ✭✭

    @ColeX

    I have changed somewhat like you said with no luck. I don't know where to add the LinkTarget for the same. Where can I see the Linker file, is it under some properties or so?

    I've shared the binding library project and the necessary SDK framework in Github

    Could you please have a look at it and let me know what is that I am doing wrong here?

  • ColeXColeX Member, Xamarin Team Xamurai

    When the .a file is added to the project, Xamarin.iOS will automatically set the Build Action of the file to ObjcBindingNativeLibrary, and create a special file called libInfColorPickerSDK.linkwith.cs.

    Check here and scroll down a little , you'll find it .

  • AnandVKAnandVK USMember ✭✭

    @ColeX , But I am trying to create from Objective C framework library with extension *.framework. Please have a look at my source shared at Github : https://github.com/ananthasivanvk/CardConnectXSDKBinding

  • AnandVKAnandVK USMember ✭✭

    I checked with card connect team and came to know that they don't support all architectures and asked me to set ObjCRuntime.Class.ThrowOnInitFailure to false and see if it works. But how to set it like that?

    @ColeX - Do you know - How do we set ObjCRuntime.Class.ThrowOnInitFailure to false, if so could you please help?

  • AnandVKAnandVK USMember ✭✭

    Got it you need to give it like ObjCRuntime.Class.ThrowOnInitFailure = false; before the statement where you actually call that specific class or method.

  • AnandVKAnandVK USMember ✭✭

    I am facing the below error after I change the ObjCRuntime.Class.ThrowOnInitFailure to false,

    ObjCRuntime.RuntimeException: Can't register the class CardConnect.CCCPaymentController when the dynamic registrar has been linked away.

    The solution mentioned for a similar issue in xamarin forums (https://forums.xamarin.com/discussion/comment/363715#Comment_363715) is not solving my issue.

  • AnandVKAnandVK USMember ✭✭
    Accepted Answer

    Adding “Additional mtouch arguments” = “--optimize=-remove-dynamic-registrar” to the sample solves the issue.

    The complete solution is updated in Github

Sign In or Register to comment.