From the course: iOS and watchOS App Development: Notifications
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Ask user permission
From the course: iOS and watchOS App Development: Notifications
Ask user permission
- [Instructor] To use notifications, you must ask permission of the user. If you do not heed the user's permission settings, your app will be rejected by Apple. Fortunately, the UserNotifications framework does most of that work for you. The best place to do that is the AppDelegate, where we've already started. The line we created, I'm going to go ahead and finish that off by adding requestAuthorization. And you'll see down here, requestAuthorization options. There's two parameters here. The first is the options we'll be using. There's three basic display options you can use and I'm going to add all three. And you do that in an array or a collection. There's .alert which will give you a visible notification. You can add a sound or a haptic by using sound. And finally, the badge which gives you the little red badge on the icon. Double-click on the completion handler place marker and that'll give you a closure. And there's two identifiers here. I'm going to make them granted which tells…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.