Skip to content

Instantly share code, notes, and snippets.

@andrewwells
Last active December 14, 2015 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save andrewwells/dd78929a20b6ff9b32d8 to your computer and use it in GitHub Desktop.
Save andrewwells/dd78929a20b6ff9b32d8 to your computer and use it in GitHub Desktop.
VinliBluetooth Quick Start Guide

VinliBluetooth SDK Quick Start Guide

###Create a speedometer in under 10 minutes!

  1. Register your Apple Id so we can get you setup with the MyVinli App on TestFlight.

  2. Go to http://dev.vin.li.

    • Create a developer account.
    • Create a new app. Call it something like “Speedometer”.
    • Press the create app button on the Vinli set up page.
    • Navigate to clients.
    • Create an iOS Client from the drop down menu.
    • Note your ClientId (you’ll need this later).
    • Create a Redirect Uri, we recommend reverse domain or using your app’s full bundle identifier. Something like li.vin.speedometer://.
    • NOTE: The Redirect Uri must have a :// suffix.
  3. Go to http://my.vin.li or open the MyVinli app and create a user account if you do not have one.

  4. Create a new project in Xcode.

  5. Install cocoapods if you don't already have it (https://guides.cocoapods.org/using/getting-started.html).

    • Navigate to the project's directory in Terminal.
    pod init //this creates the Podfile
    
    • Add the following to the Podfile
     
     pod ‘VinliBluetooth’
    
    • Navigate back to the terminal
    pod install
  6. In Xcode go to Project -> Info -> URL Types and create a custom url scheme that matches your Redirect Uri, but removing the "://" suffix. (i.e. li.vin.speedometer:// becomes li.vin.speedometer).

  7. Setup AppDelegate to handle incoming URLs.

#AppDelegate.m
#import <VinliNet/VinliSDK.h>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
   	[VLSessionManager sharedManager].clientId =  YOUR_CLIENT_ID;    
   	[VLSessionManager sharedManager].redirectUri = YOUR_REDIRECT_URI;  //without the :// suffix.
   	
   	return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
   	[[VLSessionManager sharedManager] handleCustomURL:url];
   	return YES;
}
  1. Open the default ViewController.h file and Main.storyboard side by side with the assistant editor.
    • Drag and drop a UILabel on Main.storyboard
    • Hold control and drag the label to ViewController.h
#ViewController.h

@interface UIViewController : UIViewController

// Setup a label and connect it to the ViewController.
@property (weak, nonatomic) IBOutlet UILabel* speedLabel;

@end 

#ViewController.m

#import <VinliBluetooth/VinliBluetooth.h>
#import <VinliNet/VinliSDK.h>

// Declare that the ViewController implements the VNLDeviceObserving Protocol
@interface ViewController() <VNLDeviceObserving>

// Create an instance of VNLDeviceManager 
@property (nonatomic, strong) VNLDeviceManager* deviceManager;

@end

@implementation ViewController

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];


    // Use VLSessionManager to login. This can be put into viewDidAppear or associated with a button.

    [[VLSessionManager sharedManager] loginWithCompletion:^(VLSession *session, NSError *error)
     {
         if (!error)
         {
             self.deviceManager = [[VNLDeviceManager alloc] initWithAccessToken:session.accessToken];
             self.deviceManager.deviceObserver = self;
         }
     } onCancel:^{
         // Handle onCancel case
     }];
}


// Implement the following VNLDeviceObservingMethods to receive updates when Bluetooth data is received from the Bluetooth device.


- (void)deviceManagerDidInitialize:(VNLDeviceManager *)deviceManager
{
  		[deviceManager scanForDevices];
}

- (void)device:(VNLDevice *)device updatedPid:(VNLPID *)pid forProperty:(NSString *)property
{
	    if ([property isEqualToString:VNLPropertyVehicleSpeed])
	    {
	        self.speedLabel.text = [NSString stringWithFormat:@"%@ %@", pid.rawValue, pid.units];
	    }
}

@end

Done!


@dvidsilva
Copy link

In step 8. there's a typo

@property (weak, nonatomic) IBOutlet UILabel* speedLabel.

should be:

@property (weak, nonatomic) IBOutlet UILabel* speedLabel;

@dzeitman
Copy link

Also need to add:

#import < VinliNet/VinliSDK.h > to ViewController.m

@andrewwells
Copy link
Author

Thanks dzeitman. Added!

@andrewwells
Copy link
Author

Good catch dvidsilva. Fixed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment