fill out the form
Theme Color and Secondary Theme Color specify the gradient that will be shown in the Link App:
In the commands section, you can create an action and link it to a button command:
After filling out the form, click the “Register” button to register the app.
Add the following to your application’s plist file:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string></string>
<key>CFBundleURLSchemes</key>
<array>
<string>mfl-{appkey}</string>
</array>
</dict>
</array>
make sure to replace {appkey} with the app key that was assigned to you by Misfit.
When using iOS 9, the following should also be added to the plst file:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>misfitlink</string>
</array>
Finally, open your project properties and navigate to build settings -> linking and find the “other linker flags” section. Add “-ObjC” to both debug and release.
First, import the SDK:
#import <MisfitLinkSDK/MisfitLinkSDK.h>
The following code should be added to your application delegate to handle redirection to your app after the authorization process:
- (void)applicationDidBecomeActive:(UIApplication *)application {
[[MFLSession sharedInstance] handleDidBecomeActive];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
BOOL canHandle = NO;
if ([[MFLSession sharedInstance] canHandleOpenUrl:url])
{
canHandle = [[MFLSession sharedInstance] handleOpenURL:url];
}
//other logic
return canHandle;
}
The following code can be used to enable the Flash Link Button in your application using a standard UISwitch:
- (IBAction)onEnableSwitchChanged:(UISwitch *)sender
[[MFLSession sharedInstance] enableWithAppId:@"yourAppId" appSecret:@"yourAppSecret"
completion:^(NSDictionary * commandMappingDict,NSArray * supportedCommands, MFLError* error)
{
if (error)
{
//reset the status
theSwitchControl.on = [MFLSession sharedInstance].enabled;
//handle error.
return;
}
//Button Command Settings for the user.
if (commandMappingDict)
{
MFLCommand *command = [commandMappingDict objectForKey:@(MFLGestureTypeTriplePress)];
NSLog(@"command desc:%@, name:%@", command.desc, command.name);
//output: command desc:add to favorites, name:add_to_favorites, eventType: MFLGestureTypeTriplePress
}
for (MFLCommand * command in supportedCommands)
{
NSLog(@"supported command name:%@, desc: %@",command.name,command.desc);
}
}];
}
Setup a class in your project to receive events from the MFLGestureCommandDelegate. The example below uses a ViewController.
@interface MainViewController ()<MFLGestureCommandDelegate>
...
- (void)viewDidLoad {
[MFLSession sharedInstance].gestureCommandDelegate = self;
}
...
- (void) performActionByCommand:(MFLCommand *)command
completion:(void (^)(MFLActionResultType result))completion{
if ([command.name isEqualToString:@"play_pause_music"])
{
NSLog(@"Play/Pause Music!");
//Your action here.
if (your_action_failed)
{
//handle error.
completion(MFLActionResultTypeFail);
return;
}
completion(MFLActionResultTypeSuccess);
}
else if ([command.name isEqualToString:@"next_song"])
{
NSLog(@"Next Song!");
//Your action here.
if (your_action_failed)
{
//handle error.
completion(MFLActionResultTypeFail);
return;
}
completion(MFLActionResultTypeSuccess);
}
else if ([command.name isEqualToString:@"add_to_favorites"])
{
NSLog(@"Add the song to your favorites!");
//Your action here.
if (your_action_failed)
{
//handle error.
completion(MFLActionResultTypeFail);
return;
}
completion(MFLActionResultTypeSuccess);
}
else
{
completion(MFLActionResultTypeNotSet);
}
}
Note: with each instance of
[command.name isEqualToString:@"command-name"]
command-name should be replaced with a command name that you specified when setting up your Misfit Link App
Setup a class in your project to receive events from the MFLStateTrackingDelegate.
MFLStateTrackingDelegate contains two functions:
- (void) onDeviceStateChangeWithState:(MFLDeviceState)state
serialNumber:(NSString *)serialNumber;
which can be used to receive events when the connected device becomes available or unavailable, and
- (void) onServiceStateChangeWithState:(MFLServiceState)state;
which can be used to receive events if your application is disconnected from the Misfit service (or reconnected).
The example below shows how these two delegates can be used in a ViewController:
@interface MainViewController ()<MFLStateTrackingDelegate>
...
- (void)viewDidLoad {
[MFLSession sharedInstance].sessionStateDelegate = self;
}
...
- (void) onDeviceStateChangeWithState:(MFLDeviceState)state
serialNumber:(NSString *)serialNumber
{
if (state == MFLDeviceStateUnavailable){
//the device has become unavailable
}else if (state == MFLDeviceStateAvailable){
//the device has become available
}
}
- (void) onServiceStateChangeWithState:(MFLServiceState)state
{
if (state == MFLServiceStateDisabled){
//the application has been disconnected from the Misfit service
}else if (state == MFLServiceStateEnabled){
//the application has been connected to the Misfit service
}
}
The Link SDK provides two methods for changing your button command mappings:
[[MFLSession sharedInstance] updateCommandMappingByGestureType:(MFLGestureType)gestureType commandName:(NSString *)commandName
completion:^(NSDictionary * commandMappingDict,NSArray * supportedCommands, MFLError* error)
{
if (error)
{
//reset the status
theSwitchControl.on = [MFLSession sharedInstance].enabled;
//handle error.
return;
}
//Button Command Settings for the user.
if (commandMappingDict)
{
MFLCommand *command = [commandMappingDict objectForKey:@(MFLGestureTypeTriplePress)];
NSLog(@"command desc:%@, name:%@", command.desc, command.name);
//output: command desc:add to favorites , name:add_to_favorites
}
for (NSDictionary *command in supportedCommands)
{
NSLog(@"supported command name:%@, desc: %@",command[@"name"],command[@"desc"]);
}
}];
[[MFLSession sharedInstance] showGestureMappingSettingDialogWithNavigationController:(UINavigationController *)controller
completion:^(NSDictionary * commandMappingDict,NSArray * supportedCommands, MFLError* error)
{
if (error)
{
//reset the status
theSwitchControl.on = [MFLSession sharedInstance].enabled;
//handle error.
return;
}
//Button Command Settings for the user.
if (commandMappingDict)
{
MFLCommand *command = [commandMappingDict objectForKey:@(MFLGestureTypeTriplePress)];
NSLog(@"command desc:%@, name:%@", command.desc, command.name);
//output: command desc:add to favorites, name:add_to_favorites
}
for (NSDictionary *command in supportedCommands)
{
NSLog(@"supported command name:%@, desc: %@",command[@"name"],command[@"desc"]);
}
}];
There are four different gesture types available:
typedef enum {
MFLGestureTypeSinglePress,
MFLGestureTypeDoublePress,
MFLGestureTypeTriplePress,
MFLGestureTypeLongPress,
} MFLGestureType;
@interface MFLSession : NSObject
+ (MFLSession *) sharedInstance;
@property (nonatomic, strong) id<MFLGestureCommandDelegate> gestureCommandDelegate;
@property (nonatomic, weak) id<MFLStateTrackingDelegate> sessionStateDelegate;
//is the Link SDK enabled?
@property (nonatomic, readonly) BOOL enabled;
//is the Link App installed?
- (BOOL) isMisfitLinkAppInstalled;
//enable the Link SDK button service
- (void) enableWithAppId:(NSString *) appId appSecret:(NSString *) appSecret completion:(MFLCompletion) completion;
//update the button command mapping programmatically
- (void) updateCommandMappingByGestureType:(MFLGestureType)gestureType command:(NSString *)commandName
completion:(MFLCompletion) completion;
//update the button command mapping by presenting the user with a dialog window
- (void)showGestureMappingSettingDialogWithNavigationController:(UINavigationController *)controller
completion:(MFLCompletion) completion;
- (MFLCommand *) getCommandByGestureType:(MFLGestureType)gestureType;
//disable the Link SDK
- (void) disable;
- (void) refreshStatus;
//used in the application delegate to handle redirection from the Link App
- (BOOL) handleOpenURL:(NSURL *) url;
- (BOOL) canHandleOpenUrl:(NSURL *) url;
- (void) handleDidBecomeActive;
@end