iOS VoIP推送通知(PushKit)

6
我正在搜索关于VoIP推送通知的信息。以下几点对我来说仍然不清楚:
1)如果用户没有打开应用程序,然后他接到电话。有办法从通知中启动应用程序吗?
2)应用程序如何等待特定事件?例如,我的设备如何知道他接到了来自某人的电话?
3)我使用https://github.com/Hitman666/ios-voip-push中的Appdelegate文件,但在我的情况下它不起作用(出现很多错误),这里是我收到的错误预览。
谢谢

请参考如何提问,这个问题太宽泛了! - mfaani
1个回答

8

1) 如果用户还没有打开应用程序,然后他接到电话。那么有办法从通知中启动应用程序吗?

- 首次使用者必须点击应用图标并打开它,才能注册设备ID以接收推送负载。此后无需打开应用程序。当应用程序被杀死时,您也可以根据推送负载安排本地通知。

2) 应用程序如何等待特定事件?例如,我的设备如何知道我收到了来自某人的电话?

- 您必须根据推送负载安排本地通知。

3) 我正在使用https://github.com/Hitman666/ios-voip-push中的Appdelegate文件,但在我的情况下它不起作用(有很多错误),这是我得到的错误预览。

- 请参考以下代码:

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


    }

}

获取有关如何为基于VOIP的应用程序集成pushkit的更多信息。

同时使用Swift 4.0代码进行了更新。

https://github.com/hasyapanchasara/PushKit_SilentPushNotification


嘿,我需要你在VoIP通知方面的帮助。 - Ekta Padaliya
好的,你有什么问题? - Hasya
当 VoIP 通知到来时,应用程序未打开。 - Paresh. P

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接