1) 入驻开普勒,创建应用;
2) 下载客户端SDK
注意事项:下载的SDK中,有一张安全图片文件safe.jpg ,在指定路径 Kepler.bundle 下,请勿修改和移动。
将sdk文件夹(包含JDKeplerSDK.framework和Kepler.bundle)导入到工程中,并把Framework同时添加到(Build Phases->Link Binary With Libraries)中,如图。
依赖导入系统类库:如图
支持系统版本ios7.0及以上版本
在"Info.plist"中将要在外部调用的URL scheme(jdlogin)列为白名单,并且添加注册的URL Scheme,CFBundleURLSchemes的内容为 jd+你的appKey 内容如下图所示:
具体代码:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>jdlogin</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key><string>Editor</string>
<key>CFBundleURLName</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleURLSchemes</key>
<array>
<string>jdCF4FF0FBD617466C04D977EDDA69EFA6</string>
</array>
</dict>
</array>
使用说明:demo下载后导入Xcode中。
1)必须
#import
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//注册app
[[KeplerApiManager sharedKPService] asyncInitSdk:Value_AppKey secretKey:Value_AppSecret sucessCallback:^(){
}failedCallback:^(NSError *error){
}];
return YES;
}
其中appKey ,keySecret, 在开普勒第三方app申请中获取。如果初始化失败,请检查参数是否与申请时获取的参数是否一直,修改Kepler.bundle中安全图片的内容或者名称也会导致注册失败。
2)SSO登录授权回调
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
NS_AVAILABLE_IOS(4_2){
return [[KeplerApiManager getWebViewService] handleOpenURL:url];
}
3)后台检查更新模板(可选)
需要开启服务:如图:
//iOS7以后会根据获取的结果适当的调整唤醒的时间策略 --可选
- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
BOOL haveJDKeplerServiceNewContent = NO;
[self fetchJDKeplerService:&haveJDKeplerServiceNewContent];
if (haveJDKeplerServiceNewContent){
completionHandler(UIBackgroundFetchResultNewData);
} else {
completionHandler(UIBackgroundFetchResultNoData);
}
}
//--可选
- (void)fetchJDKeplerService:(BOOL *)paramFetchedJDKeplerNewContent {
[[KeplerApiManager sharedKPService] checkJDKeplerUpdate]; //检测更新模板
字段名称 | 是否必传 | 字段解释 | 取值说明 |
---|---|---|---|
type | 是 | 页面类型 |
1:代表根据商品ID打开页面地址,需要同时传sku 2:代表打开热卖页,无其他传参 3:打开导航、列表页(暂不启用) 4:代表根据url打开商品详情页,需同时传url |
sku | 否 | 商品ID |
选品时获取的商品ID Type=1时必传 |
url | 否 | 任意开普勒地址 |
开普勒支持的页面地址,包含热卖、导航、活动、单品或者第三方页面等,如果不是以上开普勒白名单的页面,会打开导航页面 Type=4时必传 |
/**
* 打开Kepler web页面
* @param params 参数
* @param parentController 父类UIViewController
* @param jumpType 跳转类型: 1代表present 2代表push
*/
- (void)openWebViewPage:(NSString *)params
withParentController:(UIViewController *)parentController
withJumpType:(NSInteger)jumpType;
范例使用:
NSString *json = @"{\"type\": \"1\",\"blockId\":\"0\"}";
[[KeplerApiManager getWebViewService] openWebViewPage:json withParentController:self withJumpType:1];
根据商品ID打开详情页
含广告跟单分拥功能
NSString * json =@"{\n \"type\" : \"1\",\n \"sku\" : \"1217499\"\n}";
[[KeplerApiManager getWebViewService] openWebViewPage:json withParentController:self withJumpType:2]
根据商品URL打开开普勒页面
仅限广告分佣url
NSString *json = @"{\"type\": \"4\",\"url\":\"http://*** \"}";
[[KeplerApiManager getWebViewService] openWebViewPage:json withParentController:self withJumpType:2];
打开热卖页
NSString *json = @"{\"type\": \"2\"}";
[[KeplerApiManager getWebViewService] openWebViewPage:json withParentController:self withJumpType:2];;
打开导航/列表页
NSString *json =@"{\n \"type\" : \"3\" }" ;
[[KeplerApiManager getWebViewService] openWebViewPage:json withParentController:self withJumpType:2];
清除登录状态
[[KeplerApiManager getWebViewService] cancelAuth];
获取Kepler token值
[[KeplerApiManager getWebViewService] keplerToken];
直接唤起登录授权界面
用户登录授权成功后会返回用户token,登录授权失败会返回对应错误信息
- (void)keplerLoginWithViewController:(UIViewController *)viewController
success:(keplerLoginSuccessCallback)successCallback
failure:(keplerLoginFailureCallback)failureCallback;