I have never used the IOS target yet, nor have I ever used Declares in general. I am thinking of developing an IOS app, but in my activity I need to use external frameworks, for example to connect to hardware such as cash drawer, receipt printer, credit card reader, etc.
For example, with the following framework, it is indicated that it is necessary to load the framework using cocoaPods or by manually adding the framework:
Is this possible using Xojo?
Ditto for this one:
You can, but you’ll need to dig into the xcframework bundle and grab just the iOS part, either ARM or Intel depending on whether you are building for the device or the simulator, respectively. Give me a minute and I’ll dig out the declares for this.
Public Function LoadFrameworkWithPath(frameworkPath As Text) As Ptr
Declare Function dlopen Lib "/usr/lib/libSystem.dylib" ( path As CString, mode As Int32 ) As Ptr
Declare Function dlerror Lib "/usr/lib/libSystem.dylib" () As CString
Const RTLD_LAZY = 1
Const RTLD_GLOBAL = 8
dim path as Text = frameworkPath
Dim result As ptr = dlopen(path.ToCString(Xojo.Core.TextEncoding.UTF8), RTLD_LAZY Or RTLD_GLOBAL )
If result = Nil Then
Dim reason As Text = Text.FromCString(dlerror(), Xojo.Core.TextEncoding.UTF8)
Dim exc As New Xojo.Core.InvalidArgumentException
exc.Reason = reason
Call it with
Dim result As Ptr = LoadFrameworkWithPath("@executable_path/Frameworks/SumUpSDK")
Problem is, I could not test it on my M1 Mac, I get this error:
incompatible platform (have ‘iOS’, need ‘iOS-sim’)
Problem reported here: Support for arm64 Simulators · Issue #106 · sumup/sumup-ios-sdk · GitHub
Ok, so there’s a few steps you’ll need to take:
- Add two post-build CopyFiles build steps. One where AppliesTo is set to Debug and the other set to Release. Both should have their Destination set to Framework Folder.
- Drag the SumUpSDK.xcframework/ios-i386_x86_64-simulator/SumUpSDK.framework into the debugging step.
- Drag the SumUpSDK.xcframework/ios-arm64_armv7/SumUpSDK.framework into the Release step.
- Make a method with the following code:
Public Sub LoadFramework(FrameworkNameOrPath as String)
Declare Function dlopen Lib "/usr/lib/libSystem.dylib" (name As CString, flags As Int32) As Ptr
Dim flags As Integer = 8
If FrameworkNameOrPath.IndexOf("/") = -1 Then
FrameworkNameOrPath = FrameworkNameOrPath.Replace(".framework", "")
FrameworkNameOrPath = "/System/Library/Frameworks/" + FrameworkNameOrPath + ".framework/" + FrameworkNameOrPath
flags = 5
If LoadedLibraries.IndexOf(FrameworkNameOrPath) = -1 Then
Call dlopen(FrameworkNameOrPath, flags)
5. …and then in the Opening event call it like this:
Wow ! Thanks a lot to both of you ! really !!
Thank you very much Greg !!