简体   繁体   English

iOS VoIP推送通知(PushKit)

[英]iOS VoIP push notifications (PushKit)

I'm searching informations about push notifications for VoIP push notifications. 我正在搜索关于VoIP推送通知的推送通知的信息。 Some point remains unclear to me : 我有点不清楚:

1) If the user has not the application opened, and then he receives a call. 1)如果用户没有打开应用程序,那么他接到一个电话。 Is there a mean to launch the applications from the notification ? 从通知中启动应用程序是否有意义?

2) How does the application wait for a specific event ? 2)应用程序如何等待特定事件? How does my device would know he receive a call from someone for example ? 例如,我的设备如何知道他接到某人的电话?

3) I use the Appdelegate file from https://github.com/Hitman666/ios-voip-push but in my case it doesn't work (many errors), here is a preview of the error i get. 3)我使用来自https://github.com/Hitman666/ios-voip-push的Appdelegate文件,但在我的情况下它不起作用(很多错误), 这里是我得到的错误的预览。

Thanks 谢谢

1) If the user has not opened the application, and then he receives a call. 1)如果用户没有打开该应用程序,则他接到一个电话。 Is there a mean to launch the applications from the notification ? 从通知中启动应用程序是否有意义?

- First time user has to tap on app icon and open it then only device id will get register to receive push kit payload. - 首次用户必须点击应用程序图标并打开它,然后只有设备ID才会注册以接收推送工具包有效负载。 then no need to open app. 然后无需打开应用程序。 It will also work when app is in killed state and you have to schedule local notification as per push kit payload. 当应用程序处于被杀死状态时,它也会起作用,您必须根据推送工具包有效负载安排本地通知。

2) How does the application wait for a specific event ? 2)应用程序如何等待特定事件? How does my device would know he receive a call from someone for example ? 例如,我的设备如何知道他接到某人的电话?

- You have to schedule local notification as per push kit payload. - 您必须根据推送工具包有效负载安排本地通知。

3) I use the Appdelegate file from https://github.com/Hitman666/ios-voip-push but in my case it doesn't work (many errors), here is a preview of the error i get. 3)我使用来自https://github.com/Hitman666/ios-voip-push的Appdelegate文件,但在我的情况下它不起作用(很多错误),这里是我得到的错误的预览。

- Refer below code - 参考下面的代码

import UIKit
import PushKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,PKPushRegistryDelegate {

    var window: UIWindow?


    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


    }

}

Get some more information about how to integrate pushkit for VOIP based app. 获取有关如何将pushkit集成到基于VOIP的应用程序的更多信息。

Just updated with Swift 4.0 code as well. 刚刚使用Swift 4.0代码进行了更新。

https://github.com/hasyapanchasara/PushKit_SilentPushNotification https://github.com/hasyapanchasara/PushKit_SilentPushNotification

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM