Alan Docs

Alan Docs

  • Home
  • Sign In

Alan iOS SDK Reference

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

  1. 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
  1. 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];
}
  1. 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];
}
  1. 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];
}
  1. 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);
    }];
}
  1. 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);
}
  • 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