接入滴滴出行SDK

最近公司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

好了,大家可以去叫车了.今天就到这里,祝大家天天开心.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容