Search
 
SCRIPT & CODE EXAMPLE
 

SWIFT

check notification permission ios swift

UNUserNotificationCenter.current().getNotificationSettings { (settings) in
        if settings.authorizationStatus == .authorized {
            // Already authorized
        }
        else {
            // Either denied or notDetermined
            UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
                (granted, error) in
                  // add your own 
                UNUserNotificationCenter.current().delegate = self
                let alertController = UIAlertController(title: "Notification Alert", message: "please enable notifications", preferredStyle: .alert)
                let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in
                    guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
                        return
                    }
                    if UIApplication.shared.canOpenURL(settingsUrl) {
                        UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
                        })
                    }
                }
                let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
                alertController.addAction(cancelAction)
                alertController.addAction(settingsAction)
                DispatchQueue.main.async {
                    self.window?.rootViewController?.present(alertController, animated: true, completion: nil)

                }
            }
        }
    }
Comment

PREVIOUS NEXT
Code Example
Swift :: objective c vs swift 
Swift :: swift remove value dictionary 
Swift :: Swift Remove an Element from an Array 
Swift :: swift struct 
Swift :: convert uiimage to swiftui image 
Swift :: swiftui tabview background color 
Swift :: UIFont.init bold 
Swift :: Swift Closures as Function Parameter 
Swift :: swift stack view scrollable 
Swift :: replace back button image swift 
Swift :: convert secondsfrom1970 to date swift 
Swift :: swift function declaration 
Swift :: swift view 
Swift :: Swiftui run action before navigationlink inside on button 
Swift :: tap to delete xcode 
Swift :: after redirect from another viewcontroller in swift 5 make full view view controller 
Swift :: set time programmatically swift 
Swift :: Swift enum With Switch Statement 
Swift :: swift output 
Swift :: rust How to pass out parameter to function from Swift FFI 
Swift :: Swift break and continue Inside Nested Loop 
Swift :: swift how to dereference unsafemutablepointer 
Swift :: swift uibutton text resets to default 
Swift :: swift navigationbar not working 
Swift :: Swift Code Blocks 
Swift :: Swift Check if an Array is Empty 
Ruby :: create image from base64 ruby 
Ruby :: rails validate uniqueness 
Ruby :: rails routes grep 
Ruby :: ruby multiline comment 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =