Bot Manager Premier SDK

Integrate with iOS Apps

This section describes the overall integration for iOS apps (in Objective-C or Swift). First you install the BMP SDK. Next, collect and send sensor data. Then configure your response codes from the edge.

Check your app's User-Agent header

Bot Manager uses your app's User-Agent to:

  • differentiate mobile app traffic from web app traffic.
  • identify the OS and version to apply rules specific to iOS or Android.
  • identify the app version to allow traffic on versions that predate Bot Manager Premier integration and to handle any other custom rules specific to app version.

We recommend that your app's User-Agent header use a standard format like application-name/version-number (platform-information).

Examples:

HelloApp/1.2.3 (iPhone; iOS 11.2.1)
MyFirstApp/1.1.2 (Android 7.0; Build/NRD90U)

Installation

Summary

Size: The SDK framework is 9.4 MB. After installing the SDK, the app binary size will be increased approximately by 300 KB.

Architectures: armv7, arm64, i386 & x86_64

Note: Architectures i386 and x86_64 are only used in the simulator and are not included in the final AppStore app. 

Requirements

  • Xcode 8 or later

  • iOS 8.0 or later

Install the SDK

  1. Install the SDK.
    Download the SDK. Drag the AkamaiBMP.framework and drop it into your XCode Project. In the Choose Options dialog box, select Copy items if needed

  2. Edit the Build Settings.
    Under the Build Settings tab, go to Linking and then under Other Linker Flags add -ObjC.

  3. Unlike Android, you do NOT need to initialize. The SDK initializes automatically for iOS.

  4. If you're working with a Swift app, integrate using an Objective-C bridging header file.

    • If you have an existing bridging header file in your project, just import the  Akamai BMP SDK header file:

      // Import the SDK header
      #import <AkamaiBMP/CYFMonitor.h>
    • If your project doesn’t have a bridging header file, create a header file and update the build settings
      1. Create an Objective-C bridging header
        • Right-click your project and select New File
        • From iOS template options, select Header File
        • Save as BridgingHeader.h in your project.
        • Import the Akamai BMP SDK header file into BridgingHeader.h

          // Import the SDK header
          #import <AkamaiBMP/CYFMonitor.h>
      2. Update the project build settings to use BridgingHeader.h file as Objective-C bridging header.
        • Click on the project in the project navigator
        • Click the Build Settings tab.
        • Select All filter and under Swift Compiler - General settings, find the Objective Bridging Header option and change its value to ${PROJECT_NAME}/BridgingHeader.h 

    Read more on Apple Developer about Importing Objective-C into Swift 

  5. Collect Sensor Data.

    Import the SDK header into your source file:

    // Import the SDK header
    #import <AkamaiBMP/CYFMonitor.h>

    Bot Manager's sensor data contains serialized behavioral data and device information. To retrieve the sensor data from the SDK call the CYFMonitor getSensorData method. Send sensor data in the REST API request, in one of the following ways, depending upon which language you're using:

    • Objective-C:
      // Get the BMP sensor data
      NSString *sensorData = [CYFMonitor getSensorData];
    • Swift:
      // Get the BMP sensor data
      let sensorData = CYFMonitor.getSensorData()

    Important: Call the getSensorData method only on REST API requests to URLs that will be configured for protection in Bot Manager Premier Mobile. Do not call the getSensorData method for non-protected URLs.

    Note that the device information doesn't contain any information that will identify this device uniquely.

  6. Send Sensor Data.

    After the sensor data is retrieved from the SDK, it should be sent in X-acf-sensor-data HTTP header as part your application's REST API (HTTP/S) request. We recommend using HTTPS for the REST API request to ensure the integrity of sensor data and prevent eavesdropping. Send the X-acf-sensor-data header only on HTTP requests to URLs configured for protection in Bot Manager Premier Mobile. Do not send the header and sensor data on every HTTP request the app makes.

    // set the sensor-data header
    [request addValue:sensorData forHTTPHeaderField:@"X-acf-sensor-data"];
  7. Evaluate the Akamai Edge Response.

    Akamai edge server inspects sensor data and takes the predefined action on the request if the request is classified as BOT, otherwise Akamai sends the request to the origin server.

    See Akamai Edge Response section on the Bot Manager Premier SDK page for more details.

Sample Code – Getting and Sending Sensor Data

The following code snippet shows how to get the sensor data and send it in the HTTP request.

// Import the SDK header
#import

//....
//....

// Example login button action
- (IBAction )loginAction: (id )sender {

     // Get the BMP sensor data
     NSString *sensorData = [CYFMonitor getSensorData];

     // Create the request.
     NSMutableURLRequest *request = [NSMutableURLRequest
          requestWithURL:[NSURLURLWithString:@"https://bmpapi.akamai.com/samples/v1/login"]];

     // set the sensor-data header
      [request addValue:sensorData forHTTPHeaderField:@"X-acf-sensor-data"];

     // send the request object using NSURLConnection or NSURLSession
}

iOS API

Class

CYFMonitor

added in Version 2.0.0

CYFMonitor provide methods to access the BMP SDK. All methods in this class are class methods and can be accessed from anywhere without creating an instance and methods can be invoked from any thread.

See the individual method details for more information.

Public Methods

getSensorData

+ (NSString * )getSensorData ;

Get the serialized user behavior data, device events and device information to be sent with the REST api that needs to be protected.

Returns:

NSString Serialized sensor data

setLogLevel

+ (void )setLogLevel: (CYFLogLevel) logLevel;

Set the log level for the Akamai BMP SDK. See CYFLogLevel for a list of valid values.

Parameters:

logLevel CYFLogLevel: A valid log level value

Enumeration

CYFLogLevel

added in Version 2.0.0

The log level to control the logging in the SDK. The values are used with CYFMonitor setLogLevel method.

Constants

CYFLogLevelInfo

Constant to log all messages from the SDK

CYFLogLevelWarn

Constant to log all warning and error messages from the SDK

CYFLogLevelError

Constant to log only error messages from the SDK

CYFLogLevelNone

Constant to log no messages from the SDK

Logging

Akamai BMP SDK logs some messages at all log levels to verify the SDK initialization. These messages are helpful in identifying any integration issue and ensure the SDK is initialized successfully. In addition to these messages, the SDK logs additional messages at info, warn and error levels, to verify and debug that the SDK is working correctly. The default log level for the SDK is to log warning and error messages only. This behavior can be changed by calling setLogLevel API.

To set the log level, call CYFMonitor setLogLevel API with one of the log level specified below:

// Set the log level to Info
[CYFMonitor setLogLevel:CYFLogLevelInfo];

These are the available logging levels:

  • CYFLogLevelInfo - Print all messages.

  • CYFLogLevelWarn - (Default) Print warning and error messages only.

  • CYFLogLevelError - Print error messages only.

  • CYFLogLevelNone - Turn off all log messages from the SDK.