# UBIiOSDemo **Repository Path**: baixingkefu/ubiiosdemo ## Basic Information - **Project Name**: UBIiOSDemo - **Description**: No description available - **Primary Language**: Objective-C - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2021-12-23 - **Last Updated**: 2022-12-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # UBI iOS 接入指南 # ## 安装配置 1. 设置xcode,需要勾选必要的后台设置 ![avatar](https://gitee.com/baixingkefu/ubiiosdemo/raw/master/ReadMeImgs/800164309451.jpg) 2. 设置工程的info.plist文件,需要有定位,和运动与健身的使用说明 ![avatar](https://gitee.com/baixingkefu/ubiiosdemo/raw/master/ReadMeImgs/801164309452.jpg) ## 系统版本要求 iOS 10+ ## SDK接入方法 需使用cocoapods第三方库管理工具引入 Podfile 引入仓库源https://gitee.com/baixingkefu/ubisdkpodspec.git, 示例如下: ```Ruby # Uncomment the next line to define jkjka global platform for your project platform :ios, '10.0' #source 'https://github.com/CocoaPods/Specs.git' source 'https://cdn.cocoapods.org' #source 'https://github.com/aliyun/aliyun-specs.git' # UbiSDK pod仓库 source source 'https://gitee.com/baixingkefu/ubisdkpodspec.git' target 'UBITestDemo' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! # Pods for UBITestDemo # UbiSDK pod 'UbmSDKPod', '0.1.11' end ``` 注意⚠️: 当source 'https://github.com/CocoaPods/Specs.git' 更新不了第三方库的话, 可以使用source 'https://cdn.cocoapods.org' 或 source 'https://github.com/aliyun/aliyun-specs.git' 来更新,使用 ‘#’注释掉之前的源。 编写完成之后执行 pod install命令。 ## Api使用 #### 1. 实例化CredentialProvider ```Objective-C // 需要引入SDK头文件 #import // 1. 首先需要获取到相应的userId 和 passportToken // 2. 初始化UBICredentialProvider需要填入passportToken和代理对象,如self UBICredentialProvider *provider = [[UBICredentialProvider alloc] initWithPassportToken:passportToken delegate:self]; // 3. 实现Provider协议方法来刷新token @interface OneClass () @end // 此处为用户需要实现的代理方法 - (NSString * _Nullable)UBICredentialRefreshPassportToken { // 网络请求刷新Token 需要同步获取token,予以返回 // 此处省略 ........ return aNewPassportToken; } ``` #### 2. 启动SDK ``` [[UBITracking.shared enableSDK:[NSString stringWithFormat:@"%ld", userId] provider:provider] onSuccess:^{ } onFailure:^(NSInteger code, NSString * _Nonnull msg) { }]; ``` #### 3. 关闭SDK ``` [UBITracking.shared disableSDKOnSuccess:^{ NSLog(@"关闭行程成功"); } onFailure:^(NSInteger code, NSString * _Nonnull msg) { NSLog(@"关闭行程失败"); }]; ``` #### 4. 手动开始行程 ``` [UBITracking.shared startTripOnSuccess:^{ } onFailure:^(NSInteger code, NSString * _Nonnull msg) { }]; ``` #### 4.1 快速开始行程 对startTrip接口(4. 手动开始行程)的封装 功能: 1.检查SDK的初始化情况,未初始化回调错误。 2.检查相关设备权限,满足条件则开启行程并回调成功结果。 3.权限不满足则会弹出权限询问框,同时回调错误。 ``` [UBITracking.shared quickStartTripOnSuccess:^{ } onFailure:^(NSInteger code, NSString * _Nonnull msg) { }]; ``` #### 5. 手动结束行程 ``` [UBITracking.shared stopTripOnSuccess:^{ NSLog(@"手动关闭行程成功"); } onFailure:^(NSInteger code, NSString * _Nonnull msg) { NSLog(@"手动关闭行程失败"); }]; ``` #### 6. 打开自动记录行程模式 ``` [[UBITracking shared] startAutoRecordOnSuccess:^{ } onFailure:^(NSInteger code, NSString * _Nonnull msg) { }]; ``` #### 6.1 快速打开自动记录行程模式 对startAutoRecord接口(6. 打开自动记录行程模式)的封装 功能: 1.检查SDK的初始化情况,未初始化回调错误。 2.检查相关设备权限,满足条件则开启行程并回调成功结果。 3.权限不满足则会弹出权限询问框,同时回调错误。 ``` [[UBITracking shared] quickStartAutoRecordOnSuccess:^{ } onFailure:^(NSInteger code, NSString * _Nonnull msg) { }]; ``` #### 7. 关闭自动记录行程模式 ``` [[UBITracking shared] stopAutoRecordOnSuccess:^{ } onFailure:^(NSInteger code, NSString * _Nonnull msg) { }]; ``` ## App权限 包括 定位权限 和 运动与健身 权限 #### 1. 权限设置 需要初始化 UBMAuthSettingController,并展示控制器,之后点击Button设置权限 ``` UBMAuthSettingController *vc = [[UBMAuthSettingController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; ``` #### 2. 权限引导 用UBMAuthGuideController类方法直接跳转,之后点击Button设置权限。(前端Web实现) ``` [UBMAuthGuideController jumpToAuthGuideWebViewByNavigation:self.navigationController]; 或者 UBMAuthGuideController *guideVc = [[UBMAuthGuideController alloc] init]; UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:guideVc]; guideVc.modalPresentationStyle = UIModalPresentationFullScreen; [UIApplication sharedApplication].keyWindow.rootViewController presentViewController:nav animated:false completion:nil]; ``` ## 历史行程 需要初始化 UBMRouteHistoryController,并展示控制器 ``` UBMRouteHistoryController *vc = [[UBMRouteHistoryController alloc] init]; vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:vc animated:YES]; ``` ## 行程 #### 1.判断当前是否有正在记录的行程 ``` // 返回BOOL,返回YES表示正在行程中,返回NO则相反 [[UBITracking shared] isTripOnGoing]; ``` #### 2.自动记录是否正在工作 ``` // 返回BOOL,返回YES表示正在工作中,返回NO则相反 [[UBITracking shared] isAutoOn]; ``` ### ErrorCode 说明 值 | 说明 ------------- | ------------- 0 | 成功 1 | 未知错误 1000 | 调用参数错误 2000 | SDK未初始化 3000 | 没有获取所需权限 4001 | 上传文件失败 4002 | 没有运行中的行程 4003 | 调用操作不是在主进程进行