2016-01-20 1 views
0

Je le code suivant:Convertir NSCalendarUnit à Swift2

var notification = UILocalNotification() 
    notification.alertBody = "Message" // text that will be displayed in the notification 
    notification.fireDate = NSDate() // right now (when notification will be fired) 
    notification.soundName = UILocalNotificationDefaultSoundName // play default sound 

    let calendar = NSCalendar.currentCalendar() 
    let components = calendar.components([.Minute], fromDate: NSDate()) 

    notification.repeatInterval = NSCalendarUnit.CalendarUnitHour // this line defines the interval at which the notification will be repeated 
    UIApplication.sharedApplication().scheduleLocalNotification(notification) 

mais il est désapprouvée. Cherché beaucoup, mais ne pouvait pas le convertir en Swift2. Quelqu'un peut-il m'aider avec la ligne:

notification.repeatInterval = NSCalendarUnit.CalendarUnitHour 
+0

Il suffit d'utiliser '.Hour' –

+0

@LeoDabus Je l'ai fait, mais cela ne fonctionne pas. Il n'envoie pas de notification =/ –

+0

Checki as-tu enregistré pour les notifications? http://stackoverflow.com/a/34575836/2303865 –

Répondre

0

Les énumérations dans Swift 2 sont beaucoup mieux alors en Objective-C.

Essayez la ligne suivante:

notification.repeatInterval = NSCalendarUnit.Hour 

Il devrait fonctionner.

+0

mais ça ne marche pas du tout =/ –

+0

Quelle erreur obtenez-vous? Cela signifie que le problème n'est pas dans cette ligne. –

+0

J'ai mis toutes les lignes ci-dessus dans 'showNotification()' func et l'appelle sur 'viewWillDisappear'. Mais il n'appelle même pas du tout –