迁移到iOS VoIP推送通知

时间:2017-03-27 07:09:20

标签: ios apple-push-notifications voip

我们有一个VoIP应用程序,我们目前正在使用标准推送通知。我们希望更新为使用PushKit和VoIP推送通知。我有点不确定如何从我们当前的标准APNS设置迁移到新的。问题:

1)我们当前的APNS生产证书是否能够向新的VoIP客户端发送推送消息?

2)我们的新VoIP推送证书是否能够将推送消息发送到现有的标准APNS应用程序(令牌)?

1 个答案:

答案 0 :(得分:3)

请参考pushkit演示 https://github.com/hasyapanchasara/PushKit_SilentPushNotification

目标c演示也在那里 https://github.com/hasyapanchasara/PushKit_SilentPushNotification/tree/master/Objective%20C%20Demo/PushKitDemoObjectiveC

下面是注册推送套件和接收pushkit有效负载的快速代码。

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", $0) }.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

相关问题