迁移到 iOS VoIP 推送通知
Migrate to iOS VoIP push notifications
我们有一个 VoIP 应用程序,我们目前在其中使用标准推送通知。我们想更新为使用 PushKit 和 VoIP 推送通知。我有点不确定如何从我们当前的标准 APNS 设置迁移到新的。问题:
1) 我们当前的 APNS 生产证书是否能够向新的 VoIP 客户端发送推送消息?
2) 我们新的 VoIP 推送证书是否能够将推送消息发送到现有的标准 APNS 应用程序(令牌)?
请参考 pushkit demo https://github.com/hasyapanchasara/PushKit_SilentPushNotification
Objective c demo 也有 https://github.com/hasyapanchasara/PushKit_SilentPushNotification/tree/master/Objective%20C%20Demo/PushKitDemoObjectiveC
下面是 swift 注册推送工具包和接收推送工具包负载的代码。
import UIKit
import PushKit
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate{
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
application.registerForRemoteNotificationTypes(types)
self. PushKitRegistration()
return true
}
//MARK: - PushKitRegistration
func PushKitRegistration()
{
let mainQueue = dispatch_get_main_queue()
// Create a push registry object
if #available(iOS 8.0, *) {
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
// Set the registry's delegate to self
voipRegistry.delegate = self
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [PKPushTypeVoIP]
} else {
// Fallback on earlier versions
}
}
@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
// Register VoIP push token (a property of PKPushCredentials) with server
let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes),
count: credentials.token.length).map { String(format: "%02x", [=10=]) }.joinWithSeparator("")
print(hexString)
}
@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
// Process the received push
// From here you have to schedule your local notification
}
}
当您的应用程序基于 VOIP 时,一旦您收到 pushkit 负载,您就可以安排本地通知。根据您可以接收的交互式本地通知,可以处理断开连接等功能(与 Whatsapp、Skype 等相同)。
1) 我们当前的 APNS 生产证书是否能够向新的 VoIP 客户端发送推送消息?
- 不行,你必须创建 pem 文件并在后端进行配置。
2) 我们新的 VoIP 推送证书是否能够将推送消息发送到现有的标准 APNS 应用程序(令牌)?
- 不,Pushkit 令牌将不同于 APNS 令牌。
- 列表项
调试、证书、本地通知请参考更多
https://github.com/hasyapanchasara/PushKit_SilentPushNotification
我们有一个 VoIP 应用程序,我们目前在其中使用标准推送通知。我们想更新为使用 PushKit 和 VoIP 推送通知。我有点不确定如何从我们当前的标准 APNS 设置迁移到新的。问题:
1) 我们当前的 APNS 生产证书是否能够向新的 VoIP 客户端发送推送消息?
2) 我们新的 VoIP 推送证书是否能够将推送消息发送到现有的标准 APNS 应用程序(令牌)?
请参考 pushkit demo https://github.com/hasyapanchasara/PushKit_SilentPushNotification
Objective c demo 也有 https://github.com/hasyapanchasara/PushKit_SilentPushNotification/tree/master/Objective%20C%20Demo/PushKitDemoObjectiveC
下面是 swift 注册推送工具包和接收推送工具包负载的代码。
import UIKit
import PushKit
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate{
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let types: UIRemoteNotificationType = [.Alert, .Badge, .Sound]
application.registerForRemoteNotificationTypes(types)
self. PushKitRegistration()
return true
}
//MARK: - PushKitRegistration
func PushKitRegistration()
{
let mainQueue = dispatch_get_main_queue()
// Create a push registry object
if #available(iOS 8.0, *) {
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
// Set the registry's delegate to self
voipRegistry.delegate = self
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [PKPushTypeVoIP]
} else {
// Fallback on earlier versions
}
}
@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
// Register VoIP push token (a property of PKPushCredentials) with server
let hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(credentials.token.bytes),
count: credentials.token.length).map { String(format: "%02x", [=10=]) }.joinWithSeparator("")
print(hexString)
}
@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didReceiveIncomingPushWithPayload payload: PKPushPayload!, forType type: String!) {
// Process the received push
// From here you have to schedule your local notification
}
}
当您的应用程序基于 VOIP 时,一旦您收到 pushkit 负载,您就可以安排本地通知。根据您可以接收的交互式本地通知,可以处理断开连接等功能(与 Whatsapp、Skype 等相同)。
1) 我们当前的 APNS 生产证书是否能够向新的 VoIP 客户端发送推送消息?
- 不行,你必须创建 pem 文件并在后端进行配置。
2) 我们新的 VoIP 推送证书是否能够将推送消息发送到现有的标准 APNS 应用程序(令牌)?
- 不,Pushkit 令牌将不同于 APNS 令牌。
- 列表项
调试、证书、本地通知请参考更多
https://github.com/hasyapanchasara/PushKit_SilentPushNotification