Swift example from framework
  • 22 Jan 2025
  • 1 Minute à lire
  • Sombre
    Lumière
  • PDF

Swift example from framework

  • Sombre
    Lumière
  • PDF

The content is currently unavailable in French. You are viewing the default English version.
Résumé de l’article

// Callbacks.swift

import ShieldSDK

internal class Callbacks: NSObject, PRMShieldEventDelegate {

    func start() {
        PRMShieldEventManager.shared.add(observer: self)
        
        if #unavailable(iOS 16) {
            print("Developer mode status checking unavailable pre-iOS 16.")
        }
    }

    func jailbreak(status isJailbroken: Bool) {
        if isJailbroken {
            handleDeviceisJailbroken()
        }
    }

    func screenshotDetected() {
        handleScreenShotDetected()
    }
}

This is largely the same code as the previous Swift example. However, a framework usually does not implement the main AppDelegate. This means it cannot easily override didFinishLaunchingWithOptions, where you would normally call PRMShieldEventManager.shared.add(observer:).

One solution is to have the app call a function in the framework from didFinishLaunchingWithOptions, which can then call Callbacks.start(). For example:

// Callbacks.swift

import ShieldSDK

internal class Callbacks: NSObject, PRMShieldEventDelegate {

    func start() {
        PRMShieldEventManager.shared.add(observer: self)
    }
}

Of course, any other way of calling the setup early will work, as well. For example, you can use

  • an Objective-C +load static constructor, or a

  • C++ static initializer, or a

  • C __attribute__(constructor).


Cet article vous a-t-il été utile ?

Changing your password will log you out immediately. Use the new password to log back in.
First name must have atleast 2 characters. Numbers and special characters are not allowed.
Last name must have atleast 1 characters. Numbers and special characters are not allowed.
Enter a valid email
Enter a valid password
Your profile has been successfully updated.
ESC

Ozzy, facilitant la découverte de connaissances grâce à l’intelligence conversationnelle