現在、私はappDelegate
didFinishLaunchingWithOptions
に、私は次のメソッドを呼んでいる中:AppDelegate以外の場所からプッシュメッセージを受信するためにユーザーのiosデバイスを登録するにはどうすればよいですか?
let notificationTypes: UIUserNotificationType = [UIUserNotificationType.alert, UIUserNotificationType.badge, UIUserNotificationType.sound]
let pushNotificationSettings = UIUserNotificationSettings(types: notificationTypes, categories: nil)
application.registerUserNotificationSettings(pushNotificationSettings)
application.registerForRemoteNotifications()
私はまた、以下の方法がAppDelegate
で実装している:
didRegisterForRemoteNotificationsWithDeviceToken
didFailToRegisterForRemoteNotificationsWithError
didReceiveRemoteNotification
は、ユーザーが最初に私のアプリを起動すると、彼はプッシュメッセージの受信に関する許可を彼に求めるポップアップを見る。
ユーザが[設定]メニューで特定のオプションを手動で選択するまで、このポップアップの表示を延期します。設定メニューで
私はUISwitch
を持っていると私はそれの状態にユーザーがそれを変更するたびにチェックしています:、
func messagesStateChanged(_ sender: UISwitch){
if(sender.isOn){
defaults.set("true", forKey: "popupMessages")
defaults.synchronize()
} else {
defaults.set("false", forKey: "popupMessages")
defaults.synchronize()
}
}
は、設定メニューにアプリデリゲートからpush
取り扱いを移動する方法はありますユーザはアプリを起動した直後ではなく、UISwitch
を選択したときにポップアップが表示されるようになります。また、将来、すべてのpush
の機能は、私がSettingsクラスに移動すると機能しますか?
なぜ、承認された標準化されたデザインパターンを悪化させたいのですか? – vadian