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 Server的控制台中显示。
应用启动时的指标
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进行应用开发!
发现了一个bug吗?
如果你发现了一个bug,请在我们Jira上为我们创建一个工单,并提供一些复现步骤。