最近公司app需要引入滴滴出行SDK,我看了官网,没有demo,文档不全,网上资料也很少.解决很多坑后终于成功接入了滴滴出行SDK,写下这篇博客希望有需要的同行们能够少走些弯路.
去官网下载SDK和文档
去滴滴开放平台下载后,需要 Appid与Secrect,这2个需要你们和滴滴官方联系获取.
在AppDelegate里面注册滴滴
#import "AppDelegate.h"
#import <DIOpenSDK/DIOpenSDK.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[DIOpenSDK registerApp:@"从滴滴获取到的appid" secret:@"从滴滴获取到的secret"];
return YES;
}
配置plist文件
这里面有个坑,文档里面没有写添加Required background modes这一项还有NSLocationAlwaysUsageDescription这一项,所以一点击滴滴出行的方法就崩溃,还有把enable code 设置为NO.大家看看我的plist文件对比进行配置吧.
plist在viewcontroller里面实现方法
#import "ViewController.h"
#import <DIOpenSDK/DIOpenSDK.h>
@interface ViewController ()<DIOpenSDKDelegate>
@property(nonatomic, strong)UIButton *didiButton;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_didiButton = [UIButton buttonWithType:UIButtonTypeSystem];
_didiButton.frame = CGRectMake(100, 100, 200, 100);
[self.didiButton setTitle:@"滴滴出行" forState:0];
[_didiButton addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_didiButton];
}
-(void)buttonAction
{
DIOpenSDKRegisterOptions *options = nil;
[ DIOpenSDK showDDPage:self animated:YES params:options delegate:self];
}
录屏2.gif
好了,大家可以去叫车了.今天就到这里,祝大家天天开心.
网友评论