Join Steven Lipton for an in-depth discussion in this video Unique identifiers, part of iOS and watchOS App Development: Notifications.
- [Instructor] You might've noticed something a little odd about what I just did. Go back and schedule five pizzas. And then go to Manage Notifications and check the Pending. Notice we only get one request, not five. So go ahead and stop the app, and let's talk about this. In the ViewController, head to makePizza. Now we're sending the same identifier for every notification.
That only gets us one request. And the newer notification replaces the old one. To see more requests, you change the name of the request identifier. Let's do this by tacking on a number to the end of the identifier for the makePizza interval notification. You'll first need a variable to keep track of the number. So above this, I'm going to put right here, another variable. And I'll do var pizzaNumber = 0.
And then in the makePizza, when I've created my content here, I'm going to increment this, self.pizzaNumber += 1. And then under that, I'm going to add more content, called the subtitle, which appears between the title and the body of the text. I'm going to do content.subtitle = "Pizza, and then I'll do a pound sign, Pizza #\ self.pizzaNumber.
And what I'm also going to do is take the pizzaNumber and add it to the identifier. So I'm going to put a period here and a slash, and I'll put self.pizzaNumber here, like that. Another common way to set a unique identifier is a date stamp. I'm going to go up to the Scheduled Pizza now, and go up to the content there and my identifier there, and I'm going to change the message.scheduled and I'll put another period here and then we'll do a slash, and then I'm going to use the date.
And I'm going to do it in seconds here, so I'm going to use the timeIntervalSinceReferenceDate. So I get a number of seconds since the reference date. Now, with all that in place, go ahead and build and run. Get a whole bunch of pizzas from Schedule and Make. Go ahead and manage the notifications. Now view the Pending, and you'll see you've got a lot of notifications now, and now they're starting to pop up here too.
And you can see that they're each individually a notification. You may have also noticed that it took a long time when I hit it a couple times earlier, and that's because it was read making that whole notification over again. So every time I hit it, it would replace the data that was already there in the current notification.
- Requesting user permission
- Static vs. dynamic notification content
- Sending local notifications
- Updating and removing notifications
- Creating custom notifications
- Adding categories and actions to notifications
- Pushing notifications
- Building push notification payloads: alerts and actions
- Adding service and content extensions
- Attaching rich media: images, audio, and video
- Creating watchOS notifications
Skill Level Intermediate
Apple watchOS 4 App Development Essential Trainingwith Steven Lipton3h 10m Intermediate
1. User Permissions
2. Local Notifications
3. Notification Management
4. Interacting with Notifications
5. Push Notifications
6. Push Notification Payloads
7. The Service Extensions
8. The Content Extension
9. Rich Media in Notifications
10. Apple Watch Notifications
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.