Airship 18.7.2

Airship 18.7.2

Ryan LepinskiJosh Yaganeh 维护。



Airship 18.7.2

  • Airship

Airship iOS SDK

Airship iOS SDK 为您提供了一种简单的方法,将 Airship 服务集成到您的 iOS 应用程序中。

资源

安装

要使用 Airship SDK,需要 Xcode 14.3 或更高版本。

CocoaPods

请确保您已安装< Arist ح >CocoaPods依赖管理器。您可以通过执行以下命令进行安装

$ gem install cocoapods

主要Airship库包括标准功能集,建议用于大多数场景。标准功能集包括推送、动作、应用内自动化和信息中心

示例podfile

# Airship SDK
target "<Your Target Name>" do
  pod 'Airship'
end

Airship库还包含几个子模块,可以独立安装,也可以组合安装,以满足特定功能的需求

示例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 {

}

其他安装方法

有关其他安装方法,请参阅< Arist ح >- 入门指南.

快速入门

能力

在能力部分中,为主应用程序目标启用推送通知和远程通知后台模式。

添加Airship配置文件

库使用名为 AirshipConfig.plist 的 .plist 配置文件来管理生产和开发应用程序配置文件。所有示例项目中均提供了此文件的示例副本。将此文件放置在项目中,并在 http://go.urbanairship.com 上设置以下值以符合您的应用程序。要查看所有可能的键和值,请参阅 AirshipConfig 类参考

您还可以以纯文本格式编辑此文件

    <?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