Team , I’m working on a new version of checklist , but now using swift , in my old version in Objective C i did something to show 2 informations , my list and the item , like this :
-
(void)scheduleNotification
{
UILocalNotification *existingNotification = [self notificationForThisItem];
if (existingNotification != nil) {
NSLog(@“Found an existing notification %@”, existingNotification);
[[UIApplication sharedApplication] cancelLocalNotification:existingNotification];
}if (self.shouldRemind && [self.dueDate compare:[NSDate date]] != NSOrderedAscending) {
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = self.dueDate; localNotification.timeZone = [NSTimeZone defaultTimeZone]; **localNotification.alertBody = [NSString stringWithFormat:@"%@, %@", self.checklist.name, self.text];** localNotification.soundName = UILocalNotificationDefaultSoundName; localNotification.userInfo = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:self.itemId] forKey:@"ItemID"]; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; NSLog(@"Scheduled notification %@ for ItemID %d", localNotification, self.itemId);
}
}
so , this is the code in swift , I don’t know how to do that !!!
func scheduleNotification() {
removeNotification()
if shouldRemind && dueDate > Date() {
let content = UNMutableNotificationContent()
content.title = "Reminder:"
**content.body = text**
content.sound = UNNotificationSound.default()
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(
[.month, .day, .hour, .minute], from: dueDate)
let trigger = UNCalendarNotificationTrigger(
dateMatching: components, repeats: false)
let request = UNNotificationRequest(
identifier: "\(itemID)", content: content, trigger: trigger)
let center = UNUserNotificationCenter.current()
center.add(request)
print("Scheduled notification \(request) for itemID \(itemID)")
}
}