UrbanAirship-iOS-Location 12.1.2

UrbanAirship-iOS-Location 12.1.2

David CrowMarc SciglimpagliaRyan LepinskiSwizzlerBrian 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 podes,使用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中从<code>UAMediaAttachmentExtension</code>继承。

其他安装方法

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

快速入门

关于定位的一个重要说明

自2019年春季起,苹果开始拒绝那些在其Info.plist文件中未提供使用说明的App使用或似乎使用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,通过将AirshipConfig.plist.sample复制到AirshipConfig.plist并更新应用的凭据。现在您应该能够构建、运行测试和运行示例。

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

./scripts/build.sh

持续整合将为每个提交的PR运行scripts/run_ci_tasks.sh