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
}
func PushKitRegistration()
{
let mainQueue = dispatch_get_main_queue()
if #available(iOS 8.0, *) {
let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [PKPushTypeVoIP]
} else {
}
}
@available(iOS 8.0, *)
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
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!) {
}
}
获取有关如何为基于VOIP的应用程序集成pushkit的更多信息。
同时使用Swift 4.0代码进行了更新。
https://github.com/hasyapanchasara/PushKit_SilentPushNotification