Sto cercando di aggiungere una notifica locale personalizzato, ma sto ottenendo soltanto la notifica magazzino con la mia azione:Aggiungi Notifica costume locale in ios10 - rapido 3
mio storyboard assomiglia a questo (modello standard):
ho un interno che ha UNNotificationExtensionCategory
insieme a awesomeNotification
(in Info.plist). Anche la base di questa estensione è il modello Notification Content
da iOS - Application Extension
.
Nella mia app delegato ho questo:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let center = UNUserNotificationCenter.current()
let actions = [UNNotificationAction.init(identifier: "Hey", title: "Yo", options: UNNotificationActionOptions.foreground)]
let category = UNNotificationCategory(identifier: "awesomeNotification", actions: actions, minimalActions: actions, intentIdentifiers: [], options: [])
center.setNotificationCategories([category])
center.requestAuthorization([.alert, .sound]) { (granted, error) in
}
return true
}
Nel mio viewcontroller nella applicazione principale ho la seguente azione per innescare esso:
@IBAction func sendPressed(_ sender: AnyObject) {
let content = UNMutableNotificationContent()
content.categoryIdentifier = "awesomeNotification"
content.title = "Hello"
content.body = "What up?"
content.sound = UNNotificationSound.default()
// Deliver the notification in five seconds.
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "FiveSecond", content: content, trigger: trigger)
// Schedule the notification.
let center = UNUserNotificationCenter.current()
center.add(request) { (error) in
print(error)
}
print("should have been added")
}
Modifica
Così funziona su iPhone 6s/6s +, comportamento molto strano:
vuoi dire che hai bisogno di una visualizzazione personalizzata in notificaton, giusto? –
sì, questo è quello che sto cercando di usare. – Bjarte
ho provato lo stesso ... ma non riesco a mostrare la notifica anche in 6s? Puoi mettere il tuo progetto in git? –