UrbanAirship-iOS-AppExtensions 12.1.1

UrbanAirship-iOS-AppExtensions 12.1.1

测试已测试
语言编程语言 Obj-CObjective C
许可证 NOASSERTION
发布上次发布2019年12月

Ryan LepinskiDavid CrowSwizzlerMarc SciglimpagliaBrian Batchelder维护。



  • Airship

Airship iOS SDK

Airship为iOS提供的SDK可以让您简单地将Airship服务集成到您的iOS应用中。

资源

安装

所有项目和静态库都需要Xcode 11.0+,项目必须针对iOS 11或以上版本。

CocoaPods

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

$ gem install cocoapods

在您的podfile中指定UrbanAirship-iOS-SDK,并可选地指定UrbanAirship-iOS-Location pods,使用use_frameworks!选项

use_frameworks!

# Airship SDK
target "<Your Target Name>" do
  pod 'UrbanAirship-iOS-SDK'
  # Optional: uncomment to install AirshipLocationKit
  # pod 'UrbanAirship-iOS-Location'
end

使用以下命令进行安装

$ pod install

为了充分利用iOS 10的通知附件功能,您需要在与主应用一起创建一个通知服务扩展。大部分工作已经为您完成,但由于这需要创建一个新的目标,所以还有一些额外步骤。首先创建一个新的“通知服务扩展”目标。然后,将UrbanAirship-iOS-AppExtensions添加到新目标中。

use_frameworks!

# Airship SDK
target "<Your Service Extension Target Name>" do
  pod 'UrbanAirship-iOS-AppExtensions'
end

使用以下命令进行安装

$ pod install

然后删除新扩展的所有示例源代码,并让它从UAMediaAttachmentExtension继承。

import AirshipAppExtensions

class NotificationService: UAMediaAttachmentExtension {

}

Carthage

请确保您已安装Carthage。可以使用以下命令通过Homebrew安装Carthage

$ brew update
$ brew install carthage

在cartfile中指定Airship iOS SDK。

github "urbanairship/ios-library"

在cartfile相同的目录下执行以下命令。

$ carthage update

为了利用通知附件功能,您需要在主应用旁边创建一个通知服务扩展。大部分工作已经为您完成,但由于这涉及创建新目标,所以还有一些额外步骤。

  • 在Xcode中创建一个新的iOS目标,并选择“通知服务扩展”类型。
  • 将新的AirshipAppExtensions.framework拖到您的应用项目中。
  • 在扩展的构建阶段链接到AirshipAppExtensions.framework。
  • 为AirshipAppExtensions.framework添加一个复制文件阶段,并将目标选择为“框架”。
  • 删除您新扩展的所有示例源代码。
  • 在NotificationService中从UAMediaAttachmentExtension继承。

其他安装方式

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

快速入门

关于位置的重要说明

2019年春季,苹果公司开始拒绝在《Info.plist》文件中未提供使用描述的情况下使用、或似乎使用Core Location服务的应用程序。在Airship SDK 11版本中,所有对CoreLocation的引用都已从核心库中删除,并放置在单独的位置模块中。不需要地理位置服务的开发者可以继续像以前一样使用AirshipKit,但是对于使用UALocation类的用户,请参阅位置部分以获取更新的设置说明。

警告

截至SDK 10.2和苹果当前的App Store审阅政策,在没有在Info.plist中提供地理位置使用描述的情况下构建针对AirshipKit的应用程序很可能会被拒绝。如果不需要地理位置服务,则最简单的方法是使用Airship SDK 11或更高版本。如果您正在使用以前的Airship SDK构建,您需要将使用描述字符串添加到Info.plist文件中的NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescriptionNSLocationAlwaysAndWhenInUseUsageDescription键下。

功能

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

添加Airship配置文件

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

您还可以将该文件以纯文本格式编辑。

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

当设置detectProvisioningModetrue时,库将自动检测生产模式。

高级用户可以向此.plist文件添加脚本或预处理器逻辑,以基于构建类型自动切换开发模式和生产模式键。

呼叫起飞

要启用推送通知,您需要在您的应用程序代理中添加一些内容。

    - (BOOL)application:(UIApplication *)application
            didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

        // Your other application code.....

        // Set log level for debugging config loading (optional)
        // It will be set to the value in the loaded config upon takeOff
        [UAirship setLogLevel:UALogLevelTrace];

        // Populate AirshipConfig.plist with your app's info from https://go.urbanairship.com
        // or set runtime properties here.
        UAConfig *config = [UAConfig defaultConfig];

        // You can then programmatically override the plist values:
        // config.developmentAppKey = @"YourKey";
        // etc.

        // Call takeOff (which creates the UAirship singleton)
        [UAirship takeOff:config];

        // Print out the application configuration for debugging (optional)
        UA_LDEBUG(@"Config:\n%@", [config description]);

        // Set the icon badge to zero on startup (optional)
        [[UAirship push] resetBadge];

        // User notifications will not be enabled until userPushNotificationsEnabled is
        // set YES on UAPush. Once enabled, the setting will be persisted and the user
        // will be prompted to allow notifications. You should wait for a more appropriate
        // time to enable push to increase the likelihood that the user will accept
        // notifications.
        // [UAirship push].userPushNotificationsEnabled = YES;

        return YES;
    }

在应用程序中稍后启用推送

    // 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).
    [UAirship push].userPushNotificationsEnabled = YES;

SDK开发

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

$ gem install cocoapods

安装pods

$ pod install

打开Airship.xcworkspace

$ open Airship.xcworkspace

通过复制AirshipConfig.plist.sampleAirshipConfig.plist并更新应用程序的凭证来更新Samples AirshipConfig。现在,您应该能够构建、运行测试和运行样本。

可以通过运行build.sh脚本来生成发行版

./scripts/build.sh

持续集成将在每次提交PR时运行scripts/run_ci_tasks.sh