如何用setKeepAliveTimeout方法替换UIRemoteNotificationTypeVoip方法?

时间:2016-12-28 12:39:14

标签: ios xcode voip uiapplication pushkit

在我的XCode项目中,我在setKeepAliveTimeout方法中使用了applicationDidEnterBackground方法,如下面的代码。

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];

    [application setKeepAliveTimeout:600 handler: ^{
    [self performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES];
    }];
}

它显示已弃用setKeepAliveTimeout方法,并且他们希望使用UIRemoteNotificationTypeVoip方法。

我搜索了UIRemoteNotificationTypeVoip方法,但没有给出足够的结果。即使developer.apple.com也没有该方法的文档。

问题:如何更改使用UIRemoteNotificationTypeVoip的{​​{1}}?

如果有人知道,请给我一个答案。

提前致谢!

1 个答案:

答案 0 :(得分:2)

使用以下结构来完成您的任务。

一些参考

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

enter image description here

enter image description here

使用此simplepush.php文件

使用以下命令创建pem文件并在上面的代码中使用它。

之后转到simplepush.php位置和fire命令 - > php simplepush.php

通过这种方式,您可以测试推送套件通知设置架构。

https://zeropush.com/guide/guide-to-pushkit-and-voip

https://www.raywenderlich.com/123862/push-notifications-tutorial

Download

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

}

}

通过pushkit有效负载,您可以安排本地通知。当pushkit有效负载到来时,您的应用程序将在后台或终止状态下激活,直到您的本地通知声音播放。您还可以在NSUserDefault中保留详细信息。所以在交互式本地通知或didfinishlaunching选项,你可以做任何你想做的事情。