application(_:didFinishLaunchingWithOptions :)不会在其中打印任何内容

Tay*_*red 4 swift

我正在测试一个简单的应用程序上的推送通知.目前,它所做的只是接收推送通知而不做任何其他事情.

当我尝试print()application(_:didFinishLaunchingWithOptions:)函数内部输出信息时,它拒绝打印任何东西.

我的代码:

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        print("TEST TEST TEST")
        registerForPushNotifications(application)
        print("TEST TEST TEST")
        if let notification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? [String: AnyObject] {
            print(notification)
            let aps = notification["aps"] as! [String: AnyObject]
            print(aps)
        }
        return true
    }

    func registerForPushNotifications(application: UIApplication) {
        let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil)
        application.registerUserNotificationSettings(notificationSettings)
    }
}
Run Code Online (Sandbox Code Playgroud)

函数中的所有打印行都不会向控制台打印任何内容.我已经确认他们被使用断点击中了.为什么没有印刷?

我能够找到一个使用警报的解决方法,这些工作很好,并提供了我需要的所有信息,但它无法回答为什么在控制台中没有打印任何内容.

解决方法代码:

class AppDelegate: UIResponder, UIApplicationDelegate {
    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        UIAlertView(title: "Remote Notif", message: "\(launchOptions)", delegate: nil, cancelButtonTitle: "OK").show()
        registerForPushNotifications(application)
        if let notification = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? [String: AnyObject] {
            UIAlertView(title: "Remote Notif", message: "\(notification)", delegate: nil, cancelButtonTitle: "OK").show()
            let aps = notification["aps"] as! [String: AnyObject]
            UIAlertView(title: "Remote Notif", message: "\(aps)", delegate: nil, cancelButtonTitle: "OK").show()
        }
        return true
    }

    func registerForPushNotifications(application: UIApplication) {
        let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil)
        application.registerUserNotificationSettings(notificationSettings)
    }
}
Run Code Online (Sandbox Code Playgroud)

我知道UIAlertView已被弃用,但它现在仍然可以正常工作.

一些额外信息:
它正在设备上运行.
设置运行方案,以便等待启动可执行文件(例如,用户按下推送通知).
我的.plist中的主要故事板文件基本名称是"Main"


经过进一步测试后,似乎只有当我的启动方案设置为时才会发生Wait for executable to be launched,如果设置为Automatically启动,它将打印出行.我唯一能想到的是,当从推送通知中唤醒时,控制台可能没有被启动.所以它可能是Xcode的一个错误.

NSG*_*ter 6

我发现Wait for application to be launched导致Xcode调试控制台无法启动应用程序.我不知道这是打算还是Xcode错误.尝试Launch automatically在您的方案中选择,您的调试控制台应该重新打开.更改方案后,您可能还需要重新启动xCode.