如何用 setKeepAliveTimeout 方法替换 UIRemoteNotificationTypeVoip 方法?
How to replace UIRemoteNotificationTypeVoip method with setKeepAliveTimeout method?
在我的 XCode 项目中,我在 applicationDidEnterBackground
方法中使用了 setKeepAliveTimeout
方法,如下面的代码。
- (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
也没有该方法的文档。
问题:如何在使用setKeepAliveTimeout
的地方更改UIRemoteNotificationTypeVoip
?
如果有人知道,请给我一个答案。
提前致谢!
使用以下结构来完成您的任务。
一些参考
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", [=10=]) }.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 payload,您可以安排本地通知。当 pushkit 有效载荷出现时,您的应用程序将在后台或终止状态下激活,直到您播放本地通知声音。您还可以在 NSUserDefault 中保留详细信息。因此,在交互式本地通知或带有选项的 didfinishlaunching 上,您可以做任何您想做的事情。
在我的 XCode 项目中,我在 applicationDidEnterBackground
方法中使用了 setKeepAliveTimeout
方法,如下面的代码。
- (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
也没有该方法的文档。
问题:如何在使用setKeepAliveTimeout
的地方更改UIRemoteNotificationTypeVoip
?
如果有人知道,请给我一个答案。
提前致谢!
使用以下结构来完成您的任务。
一些参考
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", [=10=]) }.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 payload,您可以安排本地通知。当 pushkit 有效载荷出现时,您的应用程序将在后台或终止状态下激活,直到您播放本地通知声音。您还可以在 NSUserDefault 中保留详细信息。因此,在交互式本地通知或带有选项的 didfinishlaunching 上,您可以做任何您想做的事情。