没有调用委托方法

时间:2015-11-14 21:17:46

标签: ios

我已经在我们的应用程序中编写了一些实现推送通知(voip pushkit)的方法。它在我为测试代码而创建的Xcode项目中工作得很好。当我将代码复制到主项目中时,一些委托方法并没有得到说明......

import UIKit
import PushKit
import AVFoundation
import CoreData
import Meteor
import Stripe

let Meteor = METDDPClient(serverURL: NSURL(string: "http://example.com/websocket")!)


@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {

    var voipRegistry:PKPushRegistry!
    let designAssets = DesignAssets()
    let stripePublishableKey: String = "xxxxx"
    var ringing: AVAudioPlayer!
    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        registerForVoIPPushes()
        return true
    }



    func registerForVoIPPushes() {

        let notificationSettings: UIUserNotificationSettings! = UIApplication.sharedApplication().currentUserNotificationSettings()

        if (notificationSettings.types == UIUserNotificationType.None) {
            let notificationTypes: UIUserNotificationType = [.Badge, .Sound, .Alert]
            let notificationSettings = UIUserNotificationSettings(forTypes: notificationTypes, categories: nil)
            UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
        }

        voipRegistry = PKPushRegistry(queue: dispatch_get_main_queue())
        voipRegistry.delegate = self
        voipRegistry.desiredPushTypes = Set([PKPushTypeVoIP])
        print("VOIP Push registered")
    }


    func pushRegistry(registry: PKPushRegistry!, didUpdatePushCredentials credentials: PKPushCredentials!, forType type: String!) {
        let voipToken: String! = credentials.token.description
        print("\n\n##### PushKit credential: \n\n", voipToken)
    }

永远不会评估最后一个方法(didUpdatePushCredentials),永远不会将令牌打印到控制台......为什么?它在测试项目中运行得非常好。

1 个答案:

答案 0 :(得分:0)

Duuuhhh,忘了添加背景模式

enter image description here