Use a framewok on IOS

Hello!

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:
https://www.star-m.jp/products/s_print/sdk/starprnt_sdk/manual/ios_objc/en/configure_application.html

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.

1 Like
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
    Raise exc
    Return nil
  end if
  
  
  Return result
End Function

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

1 Like

Ok, so there’s a few steps you’ll need to take:

  1. 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.
  2. Drag the SumUpSDK.xcframework/ios-i386_x86_64-simulator/SumUpSDK.framework into the debugging step.
  3. Drag the SumUpSDK.xcframework/ios-arm64_armv7/SumUpSDK.framework into the Release step.
  4. 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
  End If
  
  If LoadedLibraries.IndexOf(FrameworkNameOrPath) = -1 Then
    Call dlopen(FrameworkNameOrPath, flags)
    LoadedLibraries.Append FrameworkNameOrPath
  End If
  
End Sub

.
5. …and then in the Opening event call it like this:

LoadFramework("@executable_path/Frameworks/SumUpSDK.framework")
2 Likes

Wow ! Thanks a lot to both of you ! really !! :pray: :pray:

Here’s a sample project

2 Likes

Thank you very much Greg !!