iOS VoIP推送 - 无法注册

时间:2016-07-20 08:15:40

标签: ios swift apple-push-notifications code-signing

功能

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

我读到这可能是证书问题所以

  1. 创建了新的应用ID,个人资料和证书

  2. 为应用添加了背景功能

  3. 使用以下代码签署代码:代码签名身份 - iPhone分发,配置文件VoIPPushTestProfile

  4. 我正在归档代码并导出以进行临时部署。 我做错了什么???

1 个答案:

答案 0 :(得分:3)

根据您的代码,您不会要求用户获得接收推送通知的权限。您需要致电gzip.open才能这样做。