0

私はappdelegateでプッシュ通知、既にセットアップして作業を持っているが、代わりに彼らは、すぐにアプリを開くと起動有するので、私は、ユーザーがアプリにサインアップした後、彼らは別の「プッシュ通知を許可」ビューコントローラ上で起動します。 AppDelegatedidFinishLaunchingWithOptions関数内から呼び出されたときに動作しますAppDelegateの外部にプッシュ通知を登録するにはどうすればよいですか?

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

が、私:私はappDelegateregisterForPushNotifications機能を持っている

let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate 

:私はこれを行うことにより、appDelegateへの参照を作ってみました私のビューコントローラでその関数を呼び出そうとしています。関数のアプリケーション部分に渡すものがないので、エラーが発生します。

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

答えて

3

applicationには何も渡されませんか?

appDelegate.registerForPushNotifications(UIApplication.sharedApplication()) 
+0

私はそれを試してみましたが、あなたはおそらく、あなたのシミュレータをリセットする必要が@SwiftyJDあなたはおそらく、すでにあなたのアプリケーションのためにそれを承認しましたので、プッシュ通知を受信するためのアラートが – SwiftyJD

+0

をポップアップしません。 Simulator - > Reset Content and Settingsを開き、再度実行します。 – tktsubota

+0

それは助けて、それは今その画面に現れます。私はプッシュ通知をオンとオフに切り替えることができるスイッチがあります。この方法でプッシュ通知設定を切り替える方法はありますか? – SwiftyJD

関連する問題