函数
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!)
没有被调用。 这是我的代码:
import UIKit
import PushKit
import Foundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {
var window: UIWindow?
//Tried also to make it local
var voipRegistry:PKPushRegistry?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
self.registerVoipNotifications()
return true
}
func registerVoipNotifications() {
let mainQueue = dispatch_get_main_queue()
// Create a push registry object
voipRegistry = PKPushRegistry(queue: mainQueue)
// Set the registry's delegate to self
voipRegistry!.delegate = self
// Set the push type to VoIP
voipRegistry!.desiredPushTypes = [PKPushTypeVoIP]
}
func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
//1. Create the alert controller.
let alert = UIAlertController(title: "VoIPPushTest", message: "Token", preferredStyle: .Alert)
//2. Add the text field. You can configure it however you need.
alert.addTextFieldWithConfigurationHandler({ (textField) -> Void in
textField.text = "got cred"
})
//print out the VoIP token. We will use this to test the nofications.
NSLog("voip token: \(credentials.token)")
let tokenChars = UnsafePointer<CChar>(credentials.token.bytes)
var tokenString = ""
for i in 0..<credentials.token.length {
tokenString += String(format: "%02.2hhx", arguments: [tokenChars[i]])
}
print("Device Token:", tokenString)
}
//Other standard app delegate functions below without changes
看了一下可能是证书的问题
创建了新的应用 ID、配置文件和证书
为应用添加了后台功能
使用以下代码签署代码:代码签名身份 - iPhone 分发、配置文件 VoIPPushTestProfile
我正在归档代码并导出以进行临时部署。 我做错了什么???
最佳答案
根据您的代码,您不要求用户允许接收推送通知。您需要调用 UIApplication.registerUserNotificationSettings
来执行此操作。
关于iOS VoIP 推送 - 注册失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38475892/