That was easy, right? And yet it's such a great feature to have, because now your app can talk to users even when it isn't running. You want to show a step count for how far they've walked? Use a notification. You want to trigger an alert because it's their turn to play in a game? Use a notification. You want to send them marketing messages to make them buy more stuff? Actually, just don't do that, you bad person.
We’ve only scratched the surface of what notifications can do, but if you’d like to explore more advanced topics – such as attaching pictures or letting the user type responses rather than tapping buttons – see my book Advanced iOS: Volume One.
We’ll be coming back to notifications again in project 33, where CloudKit is used to create and deliver remote notifications when server data has changed.
Anyone can sit through a tutorial, but it takes actual work to remember what was taught. It’s my job to make sure you take as much from these tutorials as possible, so I’ve prepared a short review to help you check your learning.
One of the best ways to learn is to write your own code as often as possible, so here are three ways you should try your new knowledge to make sure you fully understand what’s going on:
didReceiveso that it shows different instances of
UIAlertControllerdepending on which action identifier was passed in.
alarmcategory of project 21. Give it the title “Remind me later”, and make it call
scheduleLocal()so that the same alert is shown in 24 hours. (For the purpose of these challenges, a time interval notification with 86400 seconds is good enough – that’s roughly how many seconds there are in a day, excluding summer time changes and leap seconds.)
removeAllPendingNotificationRequests()to clear any un-shown alerts, then make new alerts for future days.
SPONSORED ViRE offers discoverable way of working with regex. It provides really readable regex experience, code complete & cheat sheet, unit tests, powerful replace system, step-by-step search & replace, regex visual scheme, regex history & playground. ViRE is available on Mac & iPad.
One of the most effective motivators of success is sharing your progress with other people – when you tell folks what you're doing and what you've learned, it encourages you to come back for more, which in turn will help you reach your app development goals faster.
So, now that you've done all the hard work it's time to share your success: tell folks that you've completed this project, either by clicking the button below to start composing a tweet, or by writing your own message from scratch. This will definitely encourage you to keep learning, but it will also help other folks discover my work – thank you!
Paul Hudson is the creator of Hacking with Swift, the most comprehensive series of Swift books in the world. He's also the editor of Swift Developer News, the maintainer of the Swift Knowledge Base, and a speaker at Swift events around the world. If you're curious you can learn more here.
Link copied to your pasteboard.