2 local notifications registriert - nur 1 aktiv

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Fun Fact: Man beachte die Kommentare in Zeile 13–14

    Quellcode

    1. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    2. application.cancelAllLocalNotifications()
    3. let calendar = NSCalendar.currentCalendar()
    4. let startDate = NSDate()
    5. var notificationDate = calendar.dateByAddingUnit(NSCalendarUnit.Minute, value: 5, toDate: startDate, options: [])
    6. let localNotifaction = UILocalNotification()
    7. localNotifaction.alertTitle = "hi"
    8. localNotifaction.alertBody = "what a body!"
    9. localNotifaction.fireDate = notificationDate
    10. application.scheduleLocalNotification(localNotifaction)
    11. // Uncomment lower line to get both the local notifications at the latest print!
    12. //print(application.scheduledLocalNotifications)
    13. notificationDate = calendar.dateByAddingUnit(NSCalendarUnit.Minute, value: 10, toDate: startDate, options: [])
    14. localNotifaction.alertTitle = "hi again"
    15. localNotifaction.alertBody = "cool body"
    16. localNotifaction.fireDate = notificationDate
    17. application.scheduleLocalNotification(localNotifaction)
    18. print(application.scheduledLocalNotifications)
    19. print(application.scheduledLocalNotifications?.count)
    20. // Override point for customization after application launch.
    21. return true
    22. }
    Alles anzeigen

    Es liegt definitiv an Swift…

    Die Variante hier rennt natürlich auch erfolgreich:

    Quellcode

    1. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    2. application.cancelAllLocalNotifications()
    3. let calendar = NSCalendar.currentCalendar()
    4. let startDate = NSDate()
    5. var notificationDate = calendar.dateByAddingUnit(NSCalendarUnit.Minute, value: 5, toDate: startDate, options: [])
    6. var localNotifaction = UILocalNotification()
    7. localNotifaction.alertTitle = "hi"
    8. localNotifaction.alertBody = "what a body!"
    9. localNotifaction.fireDate = notificationDate
    10. application.scheduleLocalNotification(localNotifaction)
    11. // Uncomment lower line to get both the local notifications!
    12. //print(application.scheduledLocalNotifications)
    13. notificationDate = calendar.dateByAddingUnit(NSCalendarUnit.Minute, value: 10, toDate: startDate, options: [])
    14. localNotifaction = UILocalNotification()
    15. localNotifaction.alertTitle = "hi again"
    16. localNotifaction.alertBody = "cool body"
    17. localNotifaction.fireDate = notificationDate
    18. application.scheduleLocalNotification(localNotifaction)
    19. print(application.scheduledLocalNotifications)
    20. print(application.scheduledLocalNotifications?.count)
    21. // Override point for customization after application launch.
    22. return true
    23. }
    Alles anzeigen

    Was lernen wir daraus? Schließe nie von Funktionalität in Objective–C auf Funktionalität in Swift…
    «Applejack» "Don't you use your fancy mathematics to muddle the issue!"

    Iä-86! Iä-64! Awavauatsh fthagn!

    kmr schrieb:

    Ach, Du bist auch so ein leichtgläubiger Zeitgenosse, der alles glaubt, was irgendwelche Typen vor sich hin brabbeln. :-P
  • Marco Feltmann schrieb:

    (Schließlich wurde jetzt von Zweien im Swift Code festgestellt, dass es nur einmal drin landet – eventuell, weil das Ding via let definiert ist und mit neuerem Swift da das .copy() anders implementiert?)
    Da steht nur, dass das Objekt kopiert wird, aber nicht wie. Vermutlich übergibt die Queue die Daten an das System und liest sie von dort aus. Das muss aber nichts mit NSCopying zu tun haben.
    „Meine Komplikation hatte eine Komplikation.“