Airship iOS SDK
Airship iOS SDK 为您提供了一个简单的方法,将 Airship 服务集成到您的 iOS 应用程序中。
资源
安装
使用 Airship SDK 需要 Xcode 13.0 或更高版本。
CocoaPods
请确保您已安装CocoaPods依赖关系管理器。可以通过执行以下命令来完成此操作
$ gem install cocoapods
主要的Airship库包括标准功能集,适用于大多数用例。标准功能集包括推送、操作、应用程序内自动化和信息中心
示例podfile
# Airship SDK
target "<Your Target Name>" do
pod 'Airship'
end
Airship库还包含几个子库,可以独立安装,也可以在需要特定功能选择时组合使用
Airship/Core
:推送消息功能,包括频道、标签、命名用户和默认操作Airship/MessageCenter
:信息中心Airship/Automation
:自动化和应用程序内消息Airship/Location
:位置信息,包括地理围栏和信标Airship/ExtendedActions
:扩展操作Airship/PreferenceCenter
:设置中心Airship/Chat
:实时聊天
示例podfile
target "<Your Target Name>" do
pod 'Airship/Core'
pod 'Airship/MessageCenter'
pod 'Airship/Automation'
end
使用以下命令进行安装
$ pod install
为了利用通知附件,您需要在主应用程序旁边创建一个通知服务扩展。大部分工作已经为您完成,但由于这涉及到创建新的目标,因此有额外的步骤。首先创建一个新的“通知服务扩展”目标。然后将AirshipExtensions/NotificationService添加到新目标
# Airship SDK
target "<Your Service Extension Target Name>" do
pod 'AirshipServiceExtension'
end
使用以下命令进行安装
$ pod install
然后删除新扩展的所有虚拟源代码,并使其继承自UANotificationServiceExtension
import AirshipServiceExtension
class NotificationService: UANotificationServiceExtension {
}
其他安装方法
有关其他安装方法,请参阅入门指南。
快速入门
关于位置的注意事项
在2019年春季,苹果开始拒绝使用或看似使用Core Location服务但未在其Info.plist
文件中提供使用描述的应用程序。在Airship SDK 11中,所有对CoreLocation的引用都已从核心库中移除,并放置在了单独的位置框架中。不需要位置服务的开发者可以继续像以前一样使用Airship,但对于那些一直在使用UALocation
类的开发者,请参阅位置部分以获取更新的配置说明。
警告
从SDK 10.2版本开始,根据苹果当前的App Store审核政策,如果应用程序在构建Airship时未在Info.plist
中提供位置使用描述,很可能会被拒绝。如果不使用位置服务,避免这种情况的最简单方法是使用Airship SDK 11或更高版本。如果正在构建针对旧版Airship SDK的应用程序,需要在Info.plist
文件中添加使用描述字符串,具体在NSLocationAlwaysUsageDescription
、NSLocationWhenInUseUsageDescription
和NSLocationAlwaysAndWhenInUseUsageDescription
键下。
功能
在主应用程序目标下的功能部分中启用推送通知和远程通知后台模式。
添加航船配置文件
该库使用名为 AirshipConfig.plist
的 .plist 配置文件来管理您的生产环境和开发应用配置文件。所有示例项目中都有这个文件的示例副本。将此文件放置到您的项目中,并将以下值设置为在 http://go.urbanairship.com 中您应用中的值。要查看所有可能的关键字和值,请参阅 Config 类参考
您还可以将该文件作为纯文本进行编辑
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>detectProvisioningMode</key>
<true/>
<key>developmentAppKey</key>
<string>Your Development App Key</string>
<key>developmentAppSecret</key>
<string>Your Development App Secret</string>
<key>productionAppKey</key>
<string>Your Production App Key</string>
<key>productionAppSecret</key>
<string>Your Production App Secret</string>
</dict>
</plist>
当将 detectProvisioningMode
设置为 true
时,库将自动检测生产模式。
高级用户可以添加脚本或预处理逻辑到这个 .plist 文件,以根据构建类型自动化从开发到生产密钥的切换。
调用起飞
要启用推送通知,您需要向您的应用代理添加多个操作。
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
Airship.takeOff(launchOptions: launchOptions)
return true
}
在您的应用中稍后启用推送
// Somewhere in the app, this will enable push (setting it to NO will disable push,
// which will trigger the proper registration or de-registration code in the library).
Airship.push.userPushNotificationsEnabled = true
SDK 开发
请确保您已安装了 CocoaPods 依赖管理器。您可以通过执行以下命令来完成此操作
$ gem install cocoapods
安装 pods
$ pod install
打开 Airship.xcworkspace
$ open Airship.xcworkspace
更新样例 AirshipConfig,通过将 AirshipConfig.plist.sample
复制到 AirshipConfig.plist
并更新应用的凭据来实现。现在您应该能够构建、运行测试并运行样例。
可以通过运行 build.sh 脚本来生成发行版
./scripts/build.sh
持续集成将在每个提交的 PR 上运行 scripts/run_ci_tasks.sh