iOS Application Delegate - Mobile SDKs

iOS SDK

iOS Application Delegate

The ForterSDK needs to be initialized from the Application Delegate. As the primary root of an iOS app, the app delegate object is created early in your app's launch cycle and the initialization of the Forter SDK within the app delegate will ensure that it loads correctly when the app is active. For more information on the app delegate, please see the Offical iOS developer documentation

1. Initialize from the Application Delegate 1. Initialize from the Application Delegate

The ForterSDK needs to be initialized from the Application Delegate.

  1. Import the SDK using:
    • import ForterSDK for Swift
    • #import <ForterSDK/ForterSDK.h> for Obj-C.
  2. Retrieve your site ID from the Credentials section of Forter Portal and make sure to toggle to the correct sandbox or production environment.
  3. Initialize the ForterSDK with your site_id by adding the following line to your application delegate's :didFinishLaunchingWithOptions method:

Swift

ForterSDK.setup(withSiteId:"your_site_id")

Objective C

[ForterSDK setupWithSiteId:@"your_site_id"];

2. Add Callbacks from the Application Delegate 2. Add Callbacks from the Application Delegate

When receiving messages to your application delegate please call the corresponding methods in ForterSDK's delegate, FTRSDKApplicationDelegate.

For example, upon receiving a call to applicationDidBecomeActive(_:)

Your delegate should look like the following:

Swift

func applicationDidBecomeActive(application: UIApplication){
   FTRSDKApplicationDelegate.sharedInstance().applicationDidBecomeActive(application)
}

Objective C

-(void)applicationDidBecomeActive:(UIApplication *)application {
   [[FTRSDKApplicationDelegate sharedInstance] applicationDidBecomeActive: application];
}

Please note that if you’re using Scenes, UIKit will not call applicationDidBecomeActive.

To ensure applicationDidBecomeActive is still forwarded to ForterSDK in scene-based apps, listen for didBecomeActiveNotification instead:

Swift

NotificationCenter.default.addObserver(
   self,
   selector: #selector(handleAppDidBecomeActive),
   name: UIApplication.didBecomeActiveNotification,
   object: nil
)

@objc func handleAppDidBecomeActive(){
   FTRSDKApplicationDelegate.sharedInstance().applicationDidBecomeActive(UIApplication.shared)
}

Objective C

[[NSNotificationCenter defaultCenter] addObserver:self
   selector:@selector(handleAppDidBecomeActive)
   name:UIApplicationDidBecomeActiveNotification
   object:nil];

-(void)handleAppDidBecomeActive {
   [[FTRSDKApplicationDelegate sharedInstance] applicationDidBecomeActive:[UIApplication sharedApplication]];
}

Please make sure to call ALL the AppDelegate callbacks.