Add the framework and use App Shielding APIs

Adding the framework

When using the APIs provided by App Shielding, the header files and library must be available during compilation.

The instructions in this topic describe the process for Xcode 14.2. For other versions of Xcode, the steps can be different.

To add the framework

  1. In the project navigator, select the project with which you want to use App Shielding
  2. In the editor view, select the target with which you want to use App Shielding.
  3. Select the General tab.
  4. Drag and drop ShieldSDK.xcframework from the App Shielding package into the Frameworks, Libraries and Embedded Content item.
  5. Verify that Embed&Sign is selected in the drop-down list for ShieldSDK.xcframework.

Using App Shielding APIs in an application

If the application is using APIs provided by App Shielding, it needs access to those APIs during compilation, linking, and runtime.

To use App Shielding in an application

  1. Add the ShieldSDK.xcframework to the project as outlined in Adding the framework.
  2. Any code that is to use an App Shielding API must import ShieldSDK/Shield.h.
  3. You also need to shield the application through the OneSpan Customer Portal or OneSpan Mobile Portal.

In the shielding procedure on the OneSpan Customer Portal or OneSpan Mobile Portal, you must process Step 3. If you skip it, the App Shielding APIs will not work because App Shielding will not be injected.

Using App Shielding APIs in another framework

It is also possible to add the ShieldSDK.xcframework to another framework. To do so, you need to link ShieldSDK.xcframework, your framework, and your app.

The application into which you integrate your framework still needs to be shielded after you added the framework!

To link ShieldSDK.xcframework, your framework, and your app

  1. Link ShieldSDK.xcframework to your framework but do not embed it.
  2. Link your framework to the application and embed it.
  3. Embed ShieldSDK.xcframework into your application; linking it is not necessary but is also an option.

After linking, shield the application through the OneSpan Customer Portal or OneSpan Mobile Portal.

You can use App Shielding APIs in your framework in the same way as in an application, and you can even use it in both an application and a framework. If you use it in both, however, they will share the same instance, so any operations performed will equally affect your application and the framework.

Because ShieldCallbackManager supports only one callback observer, you must choose where you want to receive these callbacks.

For callbacks to work correctly, they need to be hooked as early as possible. Since a framework usually does not implement the main AppDelegate object, you must call a framework initialize method from the didFinishLaunchingWithOptions method of your application's AppDelegate object. For this operation to succeed, you need to ensure that the callback observer is correctly set up.

 

// Callbacks.swift
import ShieldSDK
internal class CallbacksObserver: NSObject, ShieldCallback {
    func start()  {
        ShieldCallbackManager.setObserver(self)
    }

     // Callbacks
    func jailbreakStatus(_ jailbroken: Int32) { ... }
}

 // YourFrameworkInitializer.swift
private let callbacksObserver = CallbacksObserver()

 // Call this as early as possible from your application's
 // AppDelegate's didFinishLaunchingWithOptions
 public func frameworkInit() {
     callbacksObserver.start()
 }

You can also invoke the initialization using other constructors, for example, Objective-C +load static constructor, a C++ static initializer, or a C __attribute__(constructor).