iOS VoIP 推送 - 注册失败

标签 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

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

最佳答案

根据您的代码,您不要求用户允许接收推送通知。您需要调用 UIApplication.registerUserNotificationSettings 来执行此操作。

关于iOS VoIP 推送 - 注册失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38475892/

相关文章:

ios - UITableView 重新加载数据并且 tableview 为空

ios - xcode 解析查询按钮从单元格中删除照片和文本

swift - 多边形的 SKPhysicsBody.area 不正确?

php - 如何检索推送通知 php 的 ck.pem 文件

ios - Apple Push Notification 服务服务器证书更新

ios - 当标签栏显示时 Apple TV 向下移动 viewController

ios - 我是否需要替换 NSURLConnection 以实现对仅 IPv6 服务的强制支持?

ios - 更新 TableView 上的所有单元格而不使操作太 "heavy"内存

ios - 如何在TableViewController中实现后退导航按钮?

java - 通过Java实现Apple推送通知服务