title: 安装与初始化
本篇文档介绍如何安装和初始化 SDK。
1. 使用 CocoaPods 安装 SDK
通过 Cocoapods 安装 WilddogLocation SDK 以及其依赖的 Sync 和 高德定位 SDK。
- 在 Xcode 中创建一个工程,并在 terminal 中用
cd命令进入到工程所在文件夹内,执行pod init命令; - 打开生成的
Podfile文件,在第一行声明开发平台和版本,并在随后写入要引入的库:
platform :ios, 'x.0'target 'YourAppName' dopod 'WilddogLocation'end
- 保存
Podfile,并执行pod install命令,将上述依赖安装到你的工程。
2. 初始化 Location SDK
初始化需要有高德的 API Key,以及野狗 AppID:
1. 引入头文件:
在AppDelegate.h中,引入:
#import <AMapFoundationKit/AMapFoundationKit.h>
在需要使用WilddogLocation的地方引入:
#import <WilddogCore/WilddogCore.h>#import <WilddogSync/WilddogSync.h>#import <WilddogLocation/WilddogLocation.h>
2. 设置高德 API Key:
在AppDelegate.m中的-application:didFinishLaunchingWithOptions:中添加:
[AMapServices sharedServices].apiKey = @"Your-AMap-API-Key";
3. 初始化 WilddogLocation 服务:
WilddogLocation SDK 依赖于 Wilddog Sync,所以也可以先初始化 Sync 的 App,再用 Sync App 的 Reference 来创建 WilddogLocation 服务:
// 初始化Wilddog SyncWDGOptions *option = [[WDGOptions alloc] initWithSyncURL:@"https://YourAppID.wilddogio.com"];[WDGApp configureWithOptions:option];WDGSyncReference *ref = [[WDGSync sync] reference];// 使用Sync Reference初始化Wilddog LocationWDGLocation *locationService = [[WDGLocation alloc] initWithSyncReference:ref];
