Alan Docs

Alan Docs

  • Home
  • Sign In

›Integrate

Introduction

  • Getting Started
  • Script Quickstart

Build and Test

  • Script Concepts
  • Advanced Script Concepts
  • Script Testing

Integrate

  • Alan Web SDK
  • Alan iOS SDK
  • Alan Android SDK
  • Alan Ionic Framework
  • Alan Flutter Framework
  • Alan Electron Framework
  • Alan Web Component
  • Angular
  • React
  • Vue
  • Ember
  • Vanilla JS

Launch

  • Alan Playground
  • Versioning

Additional

  • How-To
  • Platform Support
  • FAQ
  • Join the Community

Alan iOS SDK

Download

Download iOS SDK framework here

Setup

  1. Copy framework to your project copy

  2. Add framework to "Embedded Binaries" (General tab for your target) embedded

  3. Add framework to "Linked Frameworks and Libraries" (General tab for your target) linked

  4. Add NSMicrophoneUsageDescription key to Info.plist of your application (must be added to microphone access) mic

Integrate into Swift

Add this Swift snippet to your view controller

Simply import AlanSDK

import AlanSDK

Define AlanButton variable

fileprivate var button: AlanButton!

Setup AlanButton in viewDidLoad()

let config = AlanConfig(key: "YOUR_KEY_FROM_ALAN_STUDIO_HERE")
self.button = AlanButton(config: config)
self.button.translatesAutoresizingMaskIntoConstraints = false
self.view.addSubview(self.button)
let b = NSLayoutConstraint(item: self.button, attribute: .bottom, relatedBy: .equal, toItem: self.view, attribute: .bottom, multiplier: 1, constant: -40)
let r = NSLayoutConstraint(item: self.button, attribute: .right, relatedBy: .equal, toItem: self.view, attribute: .right, multiplier: 1, constant: -20)
let w = NSLayoutConstraint(item: self.button, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 64)
let h = NSLayoutConstraint(item: self.button, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.0, constant: 64)
self.view.addConstraints([b, r, w, h])

To add configuration for Alan Studio project add dataObject as a parameter to AlanConfig.

let object: [String: Any] = ["username": user.username, "password": user.password]
let config = AlanConfig(key: "YOUR_KEY_FROM_ALAN_STUDIO_HERE", dataObject: object)
self.button = AlanButton(config: config)

Integrate into Objective C

Add this Objective C snippet to your view controller

Simply import AlanSDK

@import AlanSDK;

Define AlanButton variable

@property (nonatomic) AlanButton* button;

Setup AlanButton in viewDidLoad

AlanConfig* config = [[AlanConfig alloc] initWithKey:@"YOUR_KEY_FROM_ALAN_STUDIO_HERE"];
self.button = [[AlanButton alloc] initWithConfig:config];
[self.button setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.view addSubview:self.button];
NSLayoutConstraint* b = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:-40.0];
NSLayoutConstraint* r = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:-20];
NSLayoutConstraint* w = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:64.0];
NSLayoutConstraint* h = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:64.0];
[self.view addConstraints:@[b, r, w, h]];

Run application

simulator

AlanConfig

Object that describes parameters which will be provided for AlanButton.

  1. Create new AlanConfig instance with given project key:
- (instancetype)initWithKey:(NSString *)key;
NameTypeDescription
keyNSStringProject key from Alan Studio
  1. Create new AlanConfig instance with given project key and custom data object:
- (instancetype)initWithKey:(NSString *)key dataObject:(NSDictionary *)dataObject;
NameTypeDescription
keyNSStringProject key from Alan Studio
dataObjectNSDictionaryGiven data object which will be passed to Alan Studio project

Example

AlanConfig *config = [[AlanConfig alloc] initWithKey:@"fcdb8ab082683c6b6470551acf098ef52e956eca572e1d8b807a3e2338fdd0dc/stage"];

AlanButton

This class provides a view with voice button and instance methods to communicate with Alan Studio

Create new AlanButton instance with given config object:

- (instancetype)initWithConfig:(AlanConfig *)config;
NameTypeDescription
configAlanConfigAlanConfig object for configuration which is described above
Example
@interface ViewController ()
@property (nonatomic) AlanButton *button;
@end

@implementation ViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    AlanConfig *config = [[AlanConfig alloc] initWithKey:@"fcdb8ab082683c6b6470551acf098ef52e956eca572e1d8b807a3e2338fdd0dc/stage"];
    self.button = [[AlanButton alloc] initWithConfig:config];
    [self.button setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addSubview:self.button];

    NSLayoutConstraint *right = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeRight multiplier:1 constant:-20.0];
    NSLayoutConstraint *bottom = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:-20.0];
    NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:64.0];
    NSLayoutConstraint *height = [NSLayoutConstraint constraintWithItem:self.button attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:64.0];
    [self.view addConstraints:@[right, bottom, width, height]];
}
@end

Play text via Alan:

- (void)playText:(NSString *)textString;
NameTypeDescription
textStringNSStringText to be played
Example
- (IBAction)didTapPlayButton:(id)sender
{
    NSString *play = @"someString";
    [self.button playText:play];
}

Send voice synchronized data event:

- (void)playData:(NSDictionary *)data;
NameTypeDescription
dataNSDictionaryData event to be send
Example
- (IBAction)didTapDataButton:(id)sender
{
    NSDictionary *data = @{@"someKey": @"someValue"};
    [self.button playData: data];
}

Set visual state of an application:

- (void)setVisual:(NSDictionary *)data;
NameTypeDescription
dataNSDictionaryData with visual state description
Example
- (IBAction)didTapVisualButton:(id)sender
{
    NSDictionary *visual = @{@"someScreen": @"someValue"};
    [self.button setVisual:visual];
}

Call a function from Alan Studio:

- (void)call:(NSString *)method withParams:(NSDictionary*)params callback:(void(^)(NSError *error, NSString *object))callback;
NameTypeDescription
methodNSStringFunction name
paramsNSDictionaryFunction params
callback(void(^)(NSError *error, NSString *object))Callback to handle result
Example
- (IBAction)didTapCallButton:(id)sender
{
    NSString *function = @"script::updateGPS";
    NSDictionary *params = @{@"lat": @"55.0000", @"lon": @"55.0000"};
    [self.button call:function withParams:params callback:^(NSError *error, NSString *object) {
        NSLog(@"result: %@", object);
    }];
}

Handle events from AlanSDK. Add observer for notification with name "kAlanSDKEventNotification":

Example
- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleEvent:) name:@"kAlanSDKEventNotification" object:nil];
}

- (void)handleEvent:(NSNotification*)notification
{
    NSDictionary *userInfo = notification.userInfo;
    if( userInfo == nil )
    {
        return;
    }
    NSString *jsonString = [userInfo objectForKey:@"jsonString"];
    if( jsonString == nil )
    {
        return;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *error = nil;
    id unwrapped = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
    if( error != nil )
    {
        return;
    }
    NSLog(@"unwrapped: %@", unwrapped);
}
← Alan Web SDKAlan Android SDK →
  • Download
  • Setup
  • Integrate into Swift
    • Simply import AlanSDK
    • Define AlanButton variable
    • Setup AlanButton in viewDidLoad()
  • Integrate into Objective C
    • Simply import AlanSDK
    • Define AlanButton variable
    • Setup AlanButton in viewDidLoad
    • Run application
    • AlanConfig
    • AlanButton
INTEGRATIONS
iOSAndroidWebSAPIonicFlutterElectron
SOLUTIONS
Field MaintenanceOperationsAlan Safety
DEVELOPERS
PlatformDocsGithubSign In
СOMPANY
About UsCareersBlogBrand Assets
RESOURCES
SupportContactsPrivacyTerms
AlanTM is a trademark of Alan AI, Inc.Handcrafted in Sunnyvale, California