AeroGear-Push-Swift 2.0.1

AeroGear-Push-Swift 2.0.1

测试已测试
Lang语言 SwiftSwift
许可证 Apache 2
发布最新发布2017年9月
SwiftSwift 版本3.0
SPM支持 SPM

由以下人员维护:corinne krychJulio CesarAiden KeatingDaniel PassosMassimiliano Ziccardi



  • 红帽公司

aerogear-ios-push Build Status

此模块目前使用 Xcode 8 构建,支持 iOS8、iOS9 和 iOS 10。对于 iOS7 支持,请参阅 1.x_dev 分支的 ObjC 版本

AeroGear UnifiedPush 服务器用于 iOS 推送通知注册的 SDK

这是一個用 Swift 3.0 编写的小型实用库,可帮助将 iOS 应用程序注册到 AeroGear UnifiedPush 服务器

项目信息
许可证 Apache 许可证版本 2.0
构建 使用 CocoaPods 构建
文档 https://aerogear.org/docs/unifiedpush/aerogear-push-ios/
问题跟踪器 https://issues.jboss.org/browse/AGIOS
邮件列表 aerogear-users (订阅)
aerogear-dev (订阅)

构建、测试和体验 aerogear-ios-push

  1. 克隆此项目

  2. 获取依赖项

该项目使用 OHHTTPStubs 框架来模拟其 http 网络请求,并使用 CocoaPods 来处理其依赖项。作为一个先决条件,安装 CocoaPods 并安装 pod。在项目的根目录下运行:

pod install
  1. open AeroGearPush.xcworkspace

将库添加到您的项目中

要将库添加到您的项目中,您可以使用 CocoaPods 或手动安装,无论是通过拖拽代码还是构建一个 framework 以安装到您的项目中。请参阅下面的相应部分以获取说明。

在您的 Podfile 中添加

pod 'AeroGear-Push-Swift'

然后

pod install

安装您依赖项

最后,在 Xcode 中,访问目标的能力部分并启用推送通知。

示例用法

推送注册

  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
     // setup registration
    let registration = DeviceRegistration(serverURL: URL(string: "<# URL of the running AeroGear UnifiedPush Server #>")!)

    // attemp to register
    registration.register(clientInfo: { (clientDevice: ClientDeviceInformation!) in
        // setup configuration
        clientDevice.deviceToken = deviceToken
        clientDevice.variantID = "<# Variant Id #>"
        clientDevice.variantSecret = "<# Variant Secret #>"

        // apply the token, to identify THIS device
        let currentDevice = UIDevice()

        // --optional config--
        // set some 'useful' hardware information params
        clientDevice.operatingSystem = currentDevice.systemName
        clientDevice.osVersion = currentDevice.systemVersion
        clientDevice.deviceType = currentDevice.model
        },

        success: {
            print("UnifiedPush Server registration succeeded")
        },
        failure: {(error: Error!) in
            print("failed to register, error: \(error.localizedDescription)")
        })
}

使用 plist 配置文件进行推送注册

AppDelegate.swift 文件中

  func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
     // setup registration
    let registration = DeviceRegistration(config: "pushconfig")

    // attemp to register
    registration.register(clientInfo: { (clientDevice: ClientDeviceInformation!) in
        // setup configuration
        clientDevice.deviceToken = deviceToken
        let currentDevice = UIDevice()
        // set some 'useful' hardware information params
        clientDevice.operatingSystem = currentDevice.systemName
        clientDevice.osVersion = currentDevice.systemVersion
        clientDevice.deviceType = currentDevice.model
        },       
        success: {
            print("UnifiedPush Server registration succeeded")
        },
        failure: {(error: Error!) in
            print("failed to register, error: \(error.localizedDescription)")
        })
}

在您的应用程序中,创建一个新的 pushconfig.plist 文件,并添加以下属性

<plist version="1.0">
<dict>
  <key>serverURL</key>
  <string><# URL of the running AeroGear UnifiedPush Server #></string>
  <key>variantID</key>
  <string><# Variant Id #></string>
  <key>variantSecret</key>
  <string><# Variant Secret #></string>
</dict>
</plist>

注意:如果您的 UPS 服务器安装使用 自签名证书,您可以在我们的故障排除页面找到一个快速解决方案,以及有关如何正确地在其 iOS 生产应用程序中启用它的更多信息链接。

推送分析

如果您对监视推送消息如何与您的应用程序使用相关感兴趣,您可以使用指标。这些指标在 AeroGear UnifiedPush 服务器的控制台上显示。

  • 当应用程序由于推送通知启动时发送指标
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        PushAnalytics.sendMetricsWhenAppLaunched(launchOptions: launchOptions)
        return true
    }
  • 当应用程序因推送通知从后台带到前台时发送指标
    func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        // Send metrics when app is launched due to push notification
        PushAnalytics.sendMetricsWhenAppAwoken(applicationState: application.applicationState, userInfo: userInfo)

        // Do stuff ...
        fetchCompletionHandler(UIBackgroundFetchResult.noData)
    }

AeroGear UnifiedPush 服务器

更多信息,请参阅我们的教程

文档

有关当前版本的更多详细信息,请参阅我们的文档

开发

如果您想帮助开发 AeroGear,您可以加入我们的开发者邮件列表,加入 Freenode 上的 #aerogear,或在 Twitter @aerogears 上向我们提出。

同时再花些时间浏览贡献指南

问题?

加入我们的用户邮件列表有任何问题或帮助!我们真的很希望您喜欢用 AeroGear 开发应用程序!

发现错误?

如果您发现了一个错误,请在Jira 为我们创建一个错误追踪,并提供一些复现错误的步骤。