未调用委托方法
Posted
技术标签:
【中文标题】未调用委托方法【英文标题】:Delegate method not being called 【发布时间】:2015-11-14 21:17:45 【问题描述】:我已经编写了一些方法来在我们的应用程序中实现推送通知(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】:Duuuhhh,忘记添加背景模式
【讨论】:
以上是关于未调用委托方法的主要内容,如果未能解决你的问题,请参考以下文章
UIDocumentPickerViewController - 未调用委托方法