Sto tentando di inviare una notifica locale all'ora pianificata. Ma le notifiche non vengono visualizzate sullo schermo, ma vengono visualizzate nel centro notifiche quando scorro verso il basso.
Questo è quello che sto cercando di raggiungere Questo è quello che ottengo.
iOS Swift Notifica locale non "spuntando"
Questo codice da didFinishLaunchingWithOptions di mio AppDelegate().
// Setup local push notifications
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [UIUserNotificationType.Alert, UIUserNotificationType.Badge, UIUserNotificationType.Sound], categories: nil))
scheduleNotifications()
E questo è il codice per scheduleNotifications()
func scheduleNotifications() {
// create a corresponding local notification
let notification = UILocalNotification()
// Get today's date, time and year
let calendar = NSCalendar.currentCalendar()
let components = calendar.components([NSCalendarUnit.Day, NSCalendarUnit.Month, NSCalendarUnit.Year], fromDate: NSDate())
// Sets the fire time to 2pm/1400 hours to anticipate user for lunch time
components.hour = 19
components.minute = 13
components.second = 00
notification.fireDate = components.date // Sets the fire date
notification.alertBody = "Enjoyed your lunch? Don't forget to track your expenses!"
notification.alertAction = "Add expense"
notification.repeatInterval = NSCalendarUnit.Day // Repeats the notifications daily
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
Qualsiasi aiuto sarebbe apprezzato. Grazie!
In Impostazioni iOS> La tua app è impostata correttamente? In particolare, controlla le impostazioni per 'Mostra su Blocca schermo'. Inoltre, puoi pubblicare il carico utile che stai inviando con la notifica push. – JoGoFo
Sì, è impostato per essere visualizzato sulla schermata di blocco. E cosa intendi per carico utile? Questo è tutto il codice che ho scritto per le notifiche. –
Scusa, stavo pensando a una notifica push anziché a una notifica locale, che ha un payload. Stai pianificando abbastanza nel futuro in modo che la notifica venga ricevuta _dopo_ il dispositivo viene bloccato? – JoGoFo