最近公司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
好了,大家可以去叫車了.今天就到這里,祝大家天天開心.