AirshipServiceExtension 18.7.2

AirshipServiceExtension 18.7.2

Ryan LepinskiJosh Yaganeh维护。



  • Airship

Airship iOS SDK

Airship iOS SDK 为 iOS 应用 integrate Airship 服务提供了一种简单的方法。

资源

安装

使用 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 还包含一些子spec,可以独立安装,也可以组合安装,以实现特定的功能选择

  • 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

为了利用通知附件,您需要与主应用程序一起创建一个通知服务扩展。大部分工作已经为您完成,但由于这涉及到创建一个新的目标,因此需要几个额外步骤。首先创建一个新的 "Notification Service Extension" 目标。然后将 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