プッシュ通知許諾設定の結果によってViewを表示する際にボタンテキストが消える問題の対策
4617 ワード
iOSにて、プッシュ通知許諾設定がOFFの場合に「プッシュ通知をオンにしてね」というダイアログやViewを表示するケースがあると思います。
その際に謎の現象に苦しめられたのでメモとして残しておきます。
問題
プッシュ通知許諾を確認( UNUserNotificationCenter.current().getNotificationSettings
)した上で表示するUI上のボタンテキストが表示されない。
問題発生コード
表示するUIにボタンを設定(storyboard)
Push通知許諾を確認した上でUIを表示
UNUserNotificationCenter.current().getNotificationSettings { settings in
guard settings.authorizationStatus != .authorized else { return }
let nextView = UIStoryboard(name: "second", bundle: nil).instantiateInitialViewController()
self.present(nextView!, animated: true, completion: nil)
}
実行結果
対応
presentの処理をMain Threadで実行すると文字部が表示される
UNUserNotificationCenter.current().getNotificationSettings { settings in
guard settings.authorizationStatus != .authorized else { return }
DispatchQueue.main.async {
let nextView = UIStoryboard(name: "second", bundle: nil).instantiateInitialViewController()
self.present(nextView!, animated: true, completion: nil)
}
}
おわり
一応目的の動作を満たすことは出来ました。
あまりスマートな対応とは言えないので、何か知見をお持ちの方がいらっしゃればコメントなど頂ければ幸いです。
Author And Source
この問題について(プッシュ通知許諾設定の結果によってViewを表示する際にボタンテキストが消える問題の対策), 我々は、より多くの情報をここで見つけました https://qiita.com/m_orishi/items/94bd5e9329a0f8583bc4著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .