AlanConfig
Object that describes parameters which will be provided for AlanButton.
- Create new AlanConfig instance with given project key:
- (instancetype)initWithKey:(NSString *)key;
Name | Type | Description |
key | NSString | Project key from Alan Studio |
- 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:@"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;
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:@"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;
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)playData:(NSDictionary *)data;
Name | Type | Description |
data | NSDictionary | Data 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;
Name | Type | Description |
data | NSDictionary | Data 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;
Name | Type | Description |
method | NSString | Function name |
params | NSDictionary | Function 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);
}