3

My app works perfectly on ios 10 but on ios 11 it does not push local Notification. Is there any error in my code?. I have searced a lot but couldn't find appropriate solution is this a bug in ios 11 ?

class AddReminderViewController: UIViewController , UNUserNotificationCenterDelegate{

// variables


var preControllerReference : ReminderViewController?
let center = UNUserNotificationCenter.current()   
override func viewDidLoad() {
    super.viewDidLoad()
    center.delegate = self


    center.requestAuthorization(options: [.alert, .sound]) { (granted, error) in
        // Enable or disable features based on authorization.
        if error != nil {
            print("Request authorization failed!")
        } else {
            print("Request authorization succeeded!")

        }
    }
    setReminder()

    // Do any additional setup after loading the view.
}

This is the function which is setting notification

  func setReminder(){

    let content = UNMutableNotificationContent()
    content.title = "Bee Productive"
    content.body = "Buy some time"
    content.sound = UNNotificationSound.default()
    content.categoryIdentifier = "reminder-category"
    let snoozAction = UNNotificationAction(identifier:"snooze", title: "Snooze", options:[])
    let deleteAction = UNNotificationAction(identifier:"deleteAction", title: "Delete", options:[.destructive])
    let category = UNNotificationCategory(identifier: "reminder-category", actions: [snoozAction,deleteAction], intentIdentifiers:[], options: [])
    center.setNotificationCategories([category])
    let date = self.reminderDatePicker.date
    print(date)
    let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 3, repeats: false)

    let identifier = "reminder-notification"
    let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger )
    center.add(request) { (error) in
        if let err = error {
            print("something wrong \(err)")
        }
    }
}

any idea whats wrong. Thanks in advance

  • I've had the same problem but I realised it doesn't fire only when guided access is switched on. – user829227 Nov 24 '17 at 07:41
  • you are right. I just check this and found that when i set reminder and switched on guided access after the reminder time collapse it show notification. – shahzaib vohra Nov 24 '17 at 14:17
  • so what should i do to fire notification when guided access is on – shahzaib vohra Nov 24 '17 at 14:18
  • unfortunately I have no direct solution. I used NSTimer as a replacement since my application will always be in foreground. You might want to consider using both notification and timer hand in hand if you have a more complicated scenario. – user829227 Nov 25 '17 at 15:27

0 Answers0