测试已测试 | ✗ |
Lang语言 | SwiftSwift |
许可证 | Apache 2 |
发布最新发布 | 2017年9月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由以下人员维护:corinne krych,Julio Cesar,Aiden Keating,Daniel Passos,Massimiliano Ziccardi。
此模块目前使用 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 (订阅) |
克隆此项目
获取依赖项
该项目使用 OHHTTPStubs 框架来模拟其 http 网络请求,并使用 CocoaPods 来处理其依赖项。作为一个先决条件,安装 CocoaPods 并安装 pod。在项目的根目录下运行:
pod install
要将库添加到您的项目中,您可以使用 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)")
})
}
在 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,您可以加入我们的开发者邮件列表,加入 Freenode 上的 #aerogear,或在 Twitter @aerogears 上向我们提出。
同时再花些时间浏览贡献指南
加入我们的用户邮件列表有任何问题或帮助!我们真的很希望您喜欢用 AeroGear 开发应用程序!
如果您发现了一个错误,请在Jira 为我们创建一个错误追踪,并提供一些复现错误的步骤。