UrbanAirship-iOS-SDK 12.1.2

UrbanAirship-iOS-SDK 12.1.2

测试已测试
Lang语言 Obj-CObjective C
许可 NOASSERTION
发布最后发布2019年12月

由 David Crow, Swizzler, Ryan Lepinski, Marc Sciglimpaglia, Brian Batchelder 维护。David Crow, Swizzler, Ryan Lepinski, Marc Sciglimpaglia, Brian Batchelder.



  • Airship

Airship iOS SDK

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

资源

安装

所有项目和静态库都需要 Xcode 11.0+。项目必须针对 >= iOS 11。

CocoaPods

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

$ gem install cocoapods

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

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年春季,苹果开始拒绝使用或看似使用Core Location服务但未在其Info.plist文件中提供使用描述的应用程序。在Airship SDK 11中,所有对CoreLocation的引用都已从核心库中移除,并放置在单独的位置模块中。不需要位置服务的开发人员可以继续像以前一样使用AirshipKit,但对于那些使用过UALocation类的用户,请查阅位置部分以获取更新后的设置说明。

警告

截至SDK 10.2和苹果当前的App Store评审政策,没有在Info.plist文件中提供位置使用描述的基于AirshipKit构建的应用可能被拒绝。如果不需要位置服务,为了避免这种情况,请使用Airship SDK 11或更高版本。如果基于之前的Airship SDK构建,您需要在NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescriptionNSLocationAlwaysAndWhenInUseUsageDescription键下添加使用描述字符串到您的Info.plist文件中。

功能

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

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

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

高级用户可以在此.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

更新 Samples AirshipConfig,通过将 AirshipConfig.plist.sample 复制到 AirshipConfig.plist 并更新应用的凭据。现在您应该能够构建、运行测试和运行示例。

可以通过运行 build.sh 脚本来生成分布。

./scripts/build.sh

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