CleverTapGeofence 1.0.1

CleverTapGeofence 1.0.1

aditi agrawalDarshan Pania维护。



Version License codebeat badge Language Platform iOS 10.0+ Carthage compatible

👋简介

CleverTap Geofence SDK 使用 Core Location 框架提供地理围栏功能,为 CleverTap iOS SDK。本文件列出了在您的应用程序中使用 CleverTap Geofence 的步骤。您可以使用地理围栏定制文档进一步自定义 CleverTap Geofence 的集成。

内容

📋需求

以下是在使用 CleverTap Geofence SDK 时所需的项目 -

🎉安装

通过 CocoaPods

CocoaPods 是 iOS 项目的依赖管理器。要使用 CocoaPods 将 CleverTap Geofence SDK 集成到您的 Xcode 项目中,请确保在您的 Podfile 中指定以下内容

pod 'CleverTapGeofence'

有关 CocoaPods 安装的演示应用程序,请参阅 示例应用程序

有关通过 Carthage手动 安装 CleverTap Geofence 的步骤,请查看地理围栏定制文档中的说明。

🚀集成

CleverTap Geofence 使用 Core Location API 设置地理围栏区域监控。CleverTap Geofence 将不会请求用户的位置权限。位置权限需在将用户 onboard 到应用程序时视需要请求。

1. 在 Xcode 中,为您的应用程序目标启用 Location UpdatesBackground Modes。您可以在 Xcode 中通过以下方式启用此功能:

  • 在 Xcode 项目导航器中点击您的 AppTarget
  • 单击签名与功能选项卡
  • 单击+ 功能按钮
  • 选择后台模式选项
  • 通过勾选复选框启用位置更新

Xcode Capabilities

2. 在您的Info.plist文件中,添加以下键值 -

  • NSLocationAlwaysAndWhenInUseUsageDescription,也称为隐私 - 总是和在使用时位置使用描述。这是一个允许iOS在请求用户位置权限时使用字符串描述的键。

  • NSLocationWhenInUseUsageDescription,也称为隐私 - 使用时位置使用描述。这是一个允许iOS在请求用户位置权限时使用字符串描述的键。

  • UIBackgroundModes,也称为所需的背景模式。这是一个允许包含项目数组的键。该数组应包括location,也称为应用注册位置更新,以启用后台位置监控。

仅限iOS 11:如果您的应用针对iOS 11,则除了上述提到的3个Info.plist键外,还需要以下键。如果您的应用目标为iOS 12或更高版本,则不需要以下内容 -

  • NSLocationAlwaysUsageDescription,也称为隐私 - 总是位置使用描述。这是一个允许iOS在请求用户位置权限时使用字符串描述的键。仅适用于iOS 11。

以下是一个在源代码格式中包含所有Info.plist键的示例 -

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>App needs your location to provide enhanced features.</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>App needs your location to provide enhanced features.</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>App needs your location to provide enhanced features.</string>
<key>UIBackgroundModes</key>
<array>
  <string>location</string>
  <string>remote-notification</string>
  <string>fetch</string>
  <string>processing</string>
</array>

Xcode Info.plist

3. 在您的AppDelegate文件中,导入CleverTapGeofence模块。

// Swift
import CleverTapGeofence

// Objective-C
@import CleverTapGeofence;

4. 在AppDelegate的application:didFinishLaunchingWithOptions:函数中,添加以下代码片段。确保在CleverTap Main SDK初始化之后进行Geofence SDK初始化。

// Swift
CleverTapGeofence.monitor.start(didFinishLaunchingWithOptions: launchOptions)

// Objective-C
[[CleverTapGeofence monitor] startWithDidFinishLaunchingWithOptions:launchOptions];

5. CleverTap Geofence SDK需要从用户处请求位置权限以提供地理围栏功能。应用应适时请求用户的位置权限。当CleverTap Geofence SDK检测到用户已授予位置权限时,模块才会开始执行其功能。

iOS 14更新:如果用户选择了accuracyAuthorization设置的reducedAccuracy选项,则由于应用无法可靠地利用Core Location的Region Monitoring API,CleverTap Geofence将无法按预期工作。

以下是一个应用如何请求位置权限的示例 -

// Swift
let locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()

// Objective-C 
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager requestAlwaysAuthorization];

Xcode Start Geofence Snippet

📖定制

您可以通过遵循定制文档进一步自定义CleverTap Geofence的集成。

示例用法

🆕变更日志

查阅CleverTap Geofence SDK变更日志

🤝帮助和问题

如果您有问题或疑虑,您可以通过CleverTap仪表板联系CleverTap支持团队。

📄许可

CleverTap 地理围栏是以 MIT 许可协议授权的,如 LICENSE 文件中所述。