SMessageNotiViewController.swift 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // SMessageNotiViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 2016/10/14.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. import UserNotifications
  11. class SMessageNotiViewController: UITableViewController {
  12. @IBOutlet weak var messageSwitch:UISwitch!
  13. override func viewDidLoad() {
  14. super.viewDidLoad()
  15. if #available(iOS 10.0, *){
  16. let center = UNUserNotificationCenter.current()
  17. center.getNotificationSettings(completionHandler: { (settings) in
  18. let status = settings.authorizationStatus
  19. let soundSetting = settings.soundSetting
  20. let badgeSetting = settings.badgeSetting
  21. let alertSetting = settings.alertSetting
  22. let notiSetting = settings.notificationCenterSetting
  23. let lockSetting = settings.lockScreenSetting
  24. let alertStyleSetting = settings.alertStyle
  25. DDLogDebug("status = \(status.rawValue),soundSetting = \(soundSetting.rawValue),badgeSetting = \(badgeSetting.rawValue),alertSetting = \(alertSetting.rawValue),notiSetting=\(notiSetting.rawValue),lockSetting = \(lockSetting.rawValue),alertStyleSetting=\(alertStyleSetting.rawValue)")
  26. DispatchQueue.main.async {
  27. if status == UNAuthorizationStatus.authorized {
  28. self.messageSwitch.setOn(true, animated: true)
  29. }else{
  30. self.messageSwitch.setOn(false, animated: true)
  31. }
  32. }
  33. })
  34. }else{
  35. //UIApplication.shared.currentUserNotificationSettings?.types
  36. let type = UIApplication.shared.currentUserNotificationSettings?.types
  37. if type != nil {
  38. DDLogDebug("type = \(type!)")
  39. }
  40. if type == UIUserNotificationType.alert || type == UIUserNotificationType.badge || type == UIUserNotificationType.sound {
  41. self.messageSwitch.setOn(true, animated: true)
  42. }else{
  43. self.messageSwitch.setOn(false, animated: true)
  44. }
  45. }
  46. }
  47. override func didReceiveMemoryWarning() {
  48. super.didReceiveMemoryWarning()
  49. // Dispose of any resources that can be recreated.
  50. }
  51. @IBAction func sender(_ sender: UISwitch) {
  52. DDLogDebug(sender.isOn.description)
  53. }
  54. @IBAction func clickSwitchAction(_ sender: UISwitch) {
  55. DDLogDebug(sender.isOn.description)
  56. }
  57. }