Getting started with iOS SDK

This section describes how to set up and install the iOS SDK and how to deploy a feature flag.

Step 1 - Setting up the iOS SDK

To setup iOS SDK, follow these steps:

  1. Create a CloudBees Feature Management account. See Signup Page to create an account.

  2. Get your environment key.

    • Get the key from App Settings > Environment > Key.

Step 2 - Installing the iOS SDK

For instructions on initializing the iOS package to your application., select your installation method:

CocoaPods

To install the iOS package, follow these steps:

  1. In the podfile, add the following:

    pod 'ROX'
  2. To install the Cocoapods dependencies, run the following command in the terminal:

    pod install

Carthage

To install the iOS package, follow these steps:

  1. In the cartfile, add the following:

    github "rollout/rox-ios"
  2. To install the Carthage dependencies, run the following command in the terminal:

    carthage update --platform iOS

Manual installation

To install the iOS package, follow these steps:

  1. If you are already in the manual step screen on the dashboard, click download.

  2. If for some reason you left the installation screen you can go back by clicking on Dashboard > Install Instructions.

  3. Download the zip file and open it. Place the ROX directory under your application.

  4. Add files to your project in Xcode by selecting ROXCore.framework and RoxSdk.xcodeproj.

  5. Remove ROXCore.framework from Linked Frameworks and Libraries.

  6. Click the plus sign (+) under Embedded Binaries and select both ROXCore.framework and ROX.framework.

Add the following lines of code to your application

Swift Objective-c
import ROX

public class flags : RoxContainer {
  // Define the feature flags
  let enableTutorial = RoxFlag()
    // Using a simple singleton pattern
    // a single instance should be used and injected to using classes and unit tests
  let titleColors = ROXVariant(withDefault: "White", options: ["White", "Blue", "Green", "Yellow"])
    static let INSTANCE = flags()
}

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

  //Register the flags instance
    ROX.register("", container: flags.INSTANCE)

  // Setup the environment key
  ROX.setup(withKey: <ROLLOUT_ENV_KEY>)

  return true
}

flags.INSTANCE.enableTutorial.enabled {
  // TODO: Put your code here that needs to be gated
}

  switch flags.titleColors!.value()! {
  case "White":
    print("Title color is White")
  case "Blue":
    print("Title color is Blue")
  case "Green":
    print("Title color is Green")
  case "Yellow":
    print("Title color is Yellow")
  default:
    print("Title color is default - White")
}
#import <ROXCore/ROXCore.h>
@interface flags : ROXBaseContainer
@property (nonatomic) ROXFlag* enableTutorial;
@property (nonatomic) ROXVariant* titleColors;
@end

#import "MyContainer.h"
@implementation flags

- (instancetype)init {
  self = [super init];
  if (self) {
    self.enableTutorial = [[ROXFlag alloc] init];
    self.titleColors = [[ROXVariant alloc] initWithDefault:"White" options:@[@"Blue", @"Green", @"Yellow"]];
  }
  }
  return self;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Register the flag
    [ROX register:[[flags alloc] init]];

    // Setup the environment key
    [ROX setupWithKey:@<ROLLOUT_ENV_KEY>];

    return YES;
}

[flags.enableTutorial enabled:^{
  // start the tutorial
} disabled:^{
  // skip the tutorial
}];

if ([flags.titleColors.value isEqualToString:@"Blue"]) {
    NSLog(@"Title color is Blue");
}
else if ([flags.titleColors.value isEqualToString:@"White"]) {
    NSLog(@"Title color is White");
}
else if ([flags.titleColors.value isEqualToString:@"Green"]) {
    NSLog(@"Title color is Green");
}
else if ([flags.titleColors.value isEqualToString:@"Yellow"]) {
    NSLog(@"Title color is Yellow");
}

@end

Container class registration and environment key setup

  • You cannot call Rox.setup() twice in the same runtime.

Run your application

Running the application

The flag name is automatically added to the CloudBees Feature Management dashboard after running the application.