AirshipContentExtension 版本 18.7.2

AirshipContentExtension 版本 18.7.2

Ryan LepinskiJosh Yaganeh维护。



  • Airship

Airship iOS SDK

Airship iOS SDK 可以让您以简单的方式将 Airship 服务集成到您的 iOS 应用程序中。

资源

安装

使用 Airship SDK 需要 Xcode 14.3+

CocoaPods

确保已安装 CocoaPods 依赖管理器。您可以通过执行以下命令来完成此操作

$ gem install cocoapods

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

示例 Podfile

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

Airship pod 还包含一些子规范,可以独立安装,也可以组合安装,以实现特定功能的选择

  • Airship/Core : 包含频道、标签、命名用户和默认操作的推送消息功能
  • Airship/MessageCenter : 信息中心
  • Airship/Automation : 自动化和应用内消息
  • Airship/PreferenceCenter : 偏好中心

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

}

其他安装方法

有关其他安装方法,请参阅 - 入门指南

快速入门

功能

在主要应用程序目标的功能部分启用推送通知和远程通知后台模式。

添加 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