[英]Trigger local notification permission dialog from button press in Swift
從按鈕按下觸發通知權限對話框的正確方法是什么?
所有教程都將權限對話框觸發器放置在 appDelegate 中,因此一旦加載應用程序,就會出現權限對話框。
我想你剛剛回答了你自己的問題。 將請求通知權限的代碼移動到為您的按鈕按下而調用的函數。 它可能看起來像這樣:
@IBAction func buttonPressed() {
registerUserNotificationSettings()
}
func registerUserNotificationSettings() {
let userNotificationTypes = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let settings = UIUserNotificationSettings(forTypes: userNotificationTypes, categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(settings)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.