AeroGear iOS Push
一个实用的库,有助于将 iOS 应用程序注册到 AeroGear 统一推送服务器。
项目信息 | |
---|---|
许可证 | Apache 许可证,版本 2.0 |
构建 | CocoaPods |
编程语言 | Swift 4 |
文档 | http://aerogear.org/ios/ |
问题跟踪器 | https://issues.jboss.org/browse/AGIOS |
邮件列表 | aerogear-users (订阅) |
aerogear-dev (订阅) |
目录
特性
- 在 AeroGear 统一推送服务器 上注册(编程方式和 plist)
- 向 AeroGear 统一推送服务器 发送指标
安装
CocoaPods
在您的 Podfile
中添加
pod 'AeroGearPush-Swift'
然后
pod install
来安装您的依赖项
使用方法
推送注册(编程方式)
// setup registration
let registration = DeviceRegistration(serverURL: URL(string: "<#AeroGear UnifiedPush Server URL#>")!)
// attempt 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)
// setup registration
let registration = DeviceRegistration(config: "pushconfig")
// attempt to register
registration.register(
clientInfo: { (clientDevice: ClientDeviceInformation!) in
// setup configuration
clientDevice.deviceToken = deviceToken
// apply the token, to identify THIS device
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 {
// Send metrics when app is launched due to push notification
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)
// ... Some stuffs ...
// No additional data to fetch
fetchCompletionHandler(UIBackgroundFetchResult.noData)
}
文档
有关详细信息,请参考我们的文档。
示例应用
请查看我们的示例应用
开发
如果您想帮助开发AeroGear,您可以加入我们的开发者邮件列表、加入Freenode的#aerogear或通过Twitter @aerogears联系我们。
还请花时间阅读贡献指南。
有疑问吗?
请加入我们的用户邮件列表,有任何问题或需要帮助!我们真心希望您喜欢用AeroGear进行应用程序开发!
发现了问题?
如果你发现了一个问题,请在我们网站上创建Jira工单,并提供复制问题所需的步骤。