###Create a speedometer in under 10 minutes!
-
Register your Apple Id so we can get you setup with the MyVinli App on TestFlight.
-
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.
-
Go to http://my.vin.li or open the MyVinli app and create a user account if you do not have one.
-
Create a new project in Xcode.
-
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
-
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).
-
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;
}
- 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!
In step 8. there's a typo
should be: