Digital2GO 是一家以地理位置为基础的媒体、营销和移动技术公司,专注于重定义实体场所和网络空间中的消费者互动。此 SDK 提供了与我们的 API 集成的一种简便方法,使您能够使用近距离技术构建一个全球消费者互动平台。
在整个指南中,将使用以下术语:"D2GO云平台" - 包含活动、应用等配置的 Digital2GO 后端;"应用"或"客户端应用" - 使用我们的 Digital2GO SDK 连接到 D2GO云平台的客户端应用;"D2GO API" - SDK 代表客户端应用调用的后端功能,如地理围栏和信标近距离。
SDK 为 iOS 应用提供了内置集成,包括以下功能
使用 SDK,您无需实现信标和地理围栏近距离的细节,从而节省开发时间,您还可以利用我们的近距离和会话验证确保良好的用户体验。
SDK 可在 Cocoapods 上获得,您可以通过将其添加到 Podfile 中将其包含到项目中
pod 'D2GOSDK'
将 SDK 添加为项目的依赖项并运行 pod install
之后,您可以导入 D2GOSDK 到您的 App Delegate 和其他类中,与我们的 D2GO API 进行交互。
您应该首先在 AppDelegate 中实现 D2GODelegate
协议,然后调用 D2GOClient
登录设置,使用 setAPILoginRecord()
方法,如下所示
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
if !D2GOClient.shared.didInitializeAppTokens() {
//Code execution will get here if this is the first time this app is launched with the D2GOSDK or
//if an error has occurred (refer to D2GClientReturns.badAPIcredentials case in the sample client app).
//In that case, the developer needs to use their Digital2GO assigned app user name and password.
//However, note that developers are advised NOT to store their app user name and password on their device
//but rather store them at a different location (such as a backend server) and fetch them only when needed (such as in this case).
//Recommended call sequence:
// fetchAppUserNameAndPasswordFromBackend()
// D2GOClient.shared.setAPILoginRecord(username: <app user name>, password: <app password>)
D2GOClient.shared.setAPILoginRecord(username: "<app id assigned by D2GO Cloud>", password: "<password>")
}
return D2GOClient.shared.didFinishLaunching(application, withOptions: launchOptions)
}
AppDelegate 中的其他方法也通过相应的 D2GOClient
方法路由。这包括:`handleEventsForBackgroundURLSession`、`sourceApplication` 和 `applicationDidBecomeActive`。有关更多信息,请参阅示例应用。
在您的 ViewController 类中,执行以下操作
导入 D2GOSDK
和 CoreLocation
.
为您的 ViewController 创建一个对象,并实现 D2GOClientDelegate
协议以及以下两个方法,如下所示
extension ViewController : D2GOClientDelegate {
func didFindNewOfferAd(ad: Ad) {
//Include code to handle when new offers are found by the SDK
//for example get details from the Ad's public properties/methods
//and display them to your user. Refer to sample client app.
}
func handleD2GClientReturns(clientReturn: D2GClientReturns, monitoredEntity: MonitoredEntity?) {
switch clientReturn {
//Login Codes/Errors. Refer to the full list of return codes in the sample client app
case .loginServerError:
print("An error was received from the API Login Server")
case .noLocationDetected:
print("Please allow app to access your location.")
:
:
case .badAPIcredentials:
print("Ann error occurred with your API credentials. Refresh your credentials and try again")
D2GOClient.shared.setAPILoginRecord(username: "<app id assigned by D2GO Cloud>", password: "<password>")
D2GOClient.shared.refreshAPICredentials(monitoredEntity: monitoredEntity)
//Retry logic
}
在 ViewDidLoad()
中,输入以下调用以将您的控制器设置为(分别为)D2GO 客户端代理,请求设备授权,验证您的 API 登录并设置 AWS 登录以便能够使用内建的 AWS 登录基础设施登录到应用
D2GOClient.shared.d2gClientDelegate = self
D2GOClient.shared.requestInitialDeviceManagerAuth()
D2GOClient.shared.verifyLogin()
D2GOClient.shared.setupAWS()
您可以通过联系我们的支持团队或通过您的账户经理获取您的 API 令牌,如果还不是客户,可以在这里 注册.
SDK 还包含了对我们 API 当前支持的端点的 Swift 绑定:注册、地理围栏列表、以及地理围栏和磁场近距离。您可以在我们的 文档 中找到有关这些端点的更多详细信息。
版权所有 2017 Digital2GO,Inc。