This text mostly focuses on the local notifications and what we can do in UIViewController in Notification Content Extension.
Notifications in iOS 10 got quite a lot of improvements. The first one is a higher contrast with the notification view on a Lock Screen, so it stands out more. The second one is a total customization of notification presentation.
As seen in the picture above, the notifications stand out more and are attention-grabbing.
We can put custom content in the notification: music, video, images, custom drawing and animations.
When a user is unlocking his device, the first thing a user will see when he taps on the Touch ID button are notifications that are waiting for him.
Since the lock screen unlocking procedure has also been changed, the notifications have a greater chance of getting attention from a user. To unlock a phone, the user needs to tap twice and it is during this process that notifications get a small window of opportunity for presentation.
When the phone is locked, tapping the Home button reveals Lock Screen with pending notifications for user.
Tapping on the notification on the lock screen will open associated app for that notification. Swiping the notification to the left reveals View and Clear buttons. The View button is available only if device does not support 3d Touch.
On devices with 3d Touch, the user can get preview of the content by force touching the notification, which is either on the Lock Screen or Springboard. For example, the user receives a notification about new message for him. User can Force Touch notification and open the message view. The user can then type reply directly on the lock screen, instead of opening the app.
When a notification appear on Springboard, user can swipe down on notification view and get content extension presented to him. That is possible if the app has Notification Content Extension implemented about that notification.
In addition, developers can add more than one extension to their app. They just need to create new target in Xcode project and assign a category identifier in extension’s Xcode target Info.plist file.
On the time of writing, no iPad devices has Force Touch feature. Some iPhone models in production do not have Force Touch feature. On these devices, user can reveal notification by swiping.
Developers can add actions to notifications. Actions are visible when user expand the notification.
We don’t need to have Notification Content Extension for this feature.
Developers can add actions to the notification when configuring the category object:
let cool = UNNotificationAction.init(identifier: "CoolAction", title: "Cool", options: [.foreground]) let approve = UNNotificationAction.init(identifier: "ApproveAction", title: "Approve", options: [.foreground]) let later = UNNotificationAction.init(identifier: "LaterAction", title: "Later", options: [.foreground]) let like = UNNotificationAction.init(identifier: "LikeAction", title: "Like", options: [.foreground]) let category = UNNotificationCategory.init(identifier: "CategoryId", actions: [cool, approve, later, like], intentIdentifiers: , options: )
Note that we need category identifier later, when configuring the notification content object.
Notification category needs to be created and registered with
early in the application lifecycle, preferably in app delegate.
Every notification can have several actions assigned to it. The actions will appear in an ordered fashion. If we put more notification actions that can fit in the screen real estate, user will not be able to use them.
Actions are the only way a developer can enable user to interact with the notification, because adding Gesture Recognizers or UIControl objects won’t work. UIViewController that is shown when notification is expanded does not process touch input. The default behaviour for tapping the notification view is launching the app.
Notification attachments are a new way of customising notifications. This is a convenient and easy way to add content to notifications without making an extension. With the help of
class we can attach media files to the notification. By using the options dictionary argument we can also customise the thumbnail image.