Ios 如何在AppDelegate外部注册推送通知?

Ios 如何在AppDelegate外部注册推送通知?,ios,swift,push-notification,apple-push-notifications,appdelegate,Ios,Swift,Push Notification,Apple Push Notifications,Appdelegate,我已经在appdelegate中设置并使用推送通知,但我希望在用户注册应用程序后,推送通知在单独的“允许推送通知”视图控制器上启动,而不是在应用程序打开时立即启动。我尝试通过以下操作引用appDelegate: let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 我在appDelegate中有一个registerForPushNotifications函数: func registerForP

我已经在appdelegate中设置并使用推送通知,但我希望在用户注册应用程序后,推送通知在单独的“允许推送通知”视图控制器上启动,而不是在应用程序打开时立即启动。我尝试通过以下操作引用
appDelegate

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
我在
appDelegate
中有一个
registerForPushNotifications
函数:

func registerForPushNotifications(application: UIApplication) {
    let notificationSettings = UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil)
    application.registerUserNotificationSettings(notificationSettings)
}
当从
AppDelegate
中的
didfishlaunchingwithoptions
函数中调用该函数时,该函数起作用,但是当我尝试在视图控制器上调用该函数时,我没有任何要传递给函数的应用程序部分的内容,因此我最终得到了一个错误

@IBAction func yesButtonPressed(sender: AnyObject) {
    appDelegate.registerForPushNotifications(application)
    performSegueWithIdentifier("pushToHomeSegue", sender: self)
}

您确定没有任何东西要传递给
应用程序

appDelegate.registerForPushNotifications(UIApplication.sharedApplication())

您确定没有任何东西要传递给
应用程序

appDelegate.registerForPushNotifications(UIApplication.sharedApplication())

我试过了,但是接收推送通知的警报没有弹出up@SwiftyJD您可能需要重置模拟器,因为您可能已经批准将其用于应用程序。转到模拟器->重置内容和设置并再次运行。这很有帮助,它现在显示在屏幕上。在应用程序中,我有一个开关,你可以打开和关闭推送通知。有没有办法这样切换推送通知设置?@SwiftyJD我会问另一个问题(并接受我的;)。我很确定你不能这么做。我试过了,但是接收推送通知的警报没有弹出up@SwiftyJD您可能需要重置模拟器,因为您可能已经批准将其用于应用程序。转到模拟器->重置内容和设置并再次运行。这很有帮助,它现在显示在屏幕上。在应用程序中,我有一个开关,你可以打开和关闭推送通知。有没有办法这样切换推送通知设置?@SwiftyJD我会问另一个问题(并接受我的;)。我很确定你不能这么做。