Swift example from framework
- 24 Dec 2024
- 1 Minute à lire
- SombreLumière
- PDF
Swift example from framework
- Mis à jour le 24 Dec 2024
- 1 Minute à lire
- SombreLumière
- PDF
The content is currently unavailable in French. You are viewing the default English version.
Résumé de l’article
Avez-vous trouvé ce résumé utile ?
Merci pour vos commentaires
// 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 ?