Documentation

Powered by Algolia

Alan iOS SDK

Download

  1. Open Alan iOS SDK release page on GitHub
  2. Download AlanSDK.framework.zip file from the recent release. download
  3. Extract AlanSDK.framework from the zip archive. extract

Setup

  1. Drag and drop AlanSDK.framework to your Xcode project. copy1
  2. Select "Copy items if needed" checkbox if it is not selected. copy2
  3. Select XCode project file and navigate to "General" tab. Under section "Frameworks, Libraries, and Embedded Content" find AlanSDK.framework and select "Embed & Sign" from dropdown menu. embedded
  4. Navigate to "Info" tab. Add NSMicrophoneUsageDescription key to "Info.plist" of your application (must be added to get microphone access). mic
  5. To allow background mode in your iOS application go to "Signing & Capabilities" tab and select "Audio, AirPlay, and Picture in Picture" menu item. Also background mode should be turn on in Alan Studio project (Embed Code section). mic

Integrate into Swift

Add this Swift snippet to your view controller:

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])

Run application and try Alan Button

Integrate into Objective-C

Add this Objective-C snippet to your view controller:

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 and try Alan Button

AlanConfig

Object that describes parameters which will be provided for AlanButton.

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

Example

AlanConfig *config = [[AlanConfig alloc] initWithKey:@"YOUR_KEY_FROM_ALAN_STUDIO_HERE"];

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;
Name Type Description
config AlanConfig AlanConfig 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:@"YOUR_KEY_FROM_ALAN_STUDIO_HERE"];
    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 *)text;
Name Type Description
textString NSString Text to be played
Example
- (IBAction)didTapPlayButton:(id)sender
{
    NSString *play = @"someString";
    [self.button playText:play];
}

Send voice synchronized data event:

- (void)playCommand:(NSDictionary *)command;
Name Type Description
command NSDictionary Data event to be send
Example
- (IBAction)didTapDataButton:(id)sender
{
    NSDictionary *data = @{@"someKey": @"someValue"};
    [self.button playCommand: data];
}

Set visual state of an application:

- (void)setVisualState:(NSDictionary *)visualStateData;
Name Type Description
data NSDictionary Data with visual state description
Example
- (IBAction)didTapVisualButton:(id)sender
{
    NSDictionary *visual = @{@"someScreen": @"someValue"};
    [self.button setVisualState:visual];
}

Call a function from Alan Studio:

- (void)callProjectApi:(NSString *)method withData:(NSDictionary*)data callback:(void(^)(NSError *error, NSString *object))callback;
Name Type Description
method NSString Function name
data NSDictionary Function params
callback (void(^)(NSError *error, NSString *object)) Callback to handle result
Example
- (IBAction)didTapCallButton:(id)sender
{
    NSString *function = @"script::updateGPS";
    NSDictionary *data = @{@"lat": @"55.0000", @"lon": @"55.0000"};
    [self.button callProjectApi:function withData:data 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);
}