3

在我的 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地方setKeepAliveTimeout

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

提前致谢!

4

1 回答 1

2

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

一些参考

https://github.com/hasyapanchasara/PushKit_SilentPushNotification

在此处输入图像描述

在此处输入图像描述

使用这个 simplepush.php 文件

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

之后转到 simplepush.php 位置并触发命令 -> php simplepush.php

通过这种方式,您可以测试您的推送工具包通知设置架构。

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

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

下载

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 中保留详细信息。因此,在交互式本地通知或使用选项完成启动时,您可以做任何您想做的事情。

于 2017-01-19T07:26:29.013 回答