Notifications in iOS 10

Notifications in iOS 10

The new version of iOS introduces a number of changes concerning both local and server notifications. We can use a new framework, UserNotifications, which enables both delivering and handling notifications.

Handling notifications in iOS

New notifications allow you to add images (jpg, png, gif) and videos, and to perform other actions. Moreover, we can now use Notification Content Extension through which we can design the exact appearance of notification in our application.

To handle notifications in an application, follow these steps:

  • Registering notifications (Register),
  • Setting the trigger (Trigger),
  • Creating content (Content),
  • Calling the notification (Schedule).

Step 1. Registration

Compared to previous versions of iOS, there was a change in the way of their registration:

UNUserNotificationCenter.current().requestAuthorization(options:[.alert, .sound, .badge]) { (greanted, error) in //.. }

We can now check what settings user selected for notifications in the application:

Step 2. Setting up a trigger

There are four types of triggers:

  • Push,
  • Time Interval.
UNTimeIntercalNotificationTrigger(timeInterval: 120, repeats: false)
  • Calendar,
let dateComponents = DateComponents()
// set the dateComponents here
UNCalendarNotificationTrigger( dateMatching: dateComponents, repeats: false )
  • Location,
let region - CLRegion()
// set the region here 
UNLocationNotificationTrigger( region: region, repeats: false )

Step 3. Creating the notification content

Notification content We now have greater room for maneuver, and thus can set the following: title, subtitle and body for notifications.

let content = UNMutableNotificationContent()
content.title =  "Notification title"
content.subtitle = "Notification subtitle"
content.body = "Notification body"
content.sound = UNNotificationSound.default()
content.badge = 1

Step 4. Calling the notification

Last but not least, all we need to do is to call the notification as shown below.

let requestId = "notificationRequestIdentifier1"
let request = UNNotificationRequest(identifier: requestId, content: content, trigger: triger)
UNUserNotificationCenter.current().add(request) { error in //... }

Learn more

How to Send iOS Notifications in Different Languages? Guide to Dynamic Localization

The best way to set a connection between a user, provider, and an app? System notifications. They allow users to get the latest news in no time. This solution is easy to implement in apps dedicated to one market. But it gets complicated when the messages must be displayed in many languages. In such cases, the dynamic localization of remote notifications can be a real game-changer.

Read more

Promises on the Example of PromiseKit in Objective-C

Sooner or later every programmer encounters the problem of synchronous execution of certain actions. For example: get user information from the API, parse server response, save data to the database, update the view, and many others. To make it even more, at some of these stages you still need to deal with error handling. What should you do exactly?

Read more

Project estimation

Let us know what product you want to build and how we can help you.

Why choose us?

Logo Mobile Trends Awards

Mobile Trends Awards 2021

Winning app in
EVERYDAY LIFE

Nagroda Legalnych Bukmacherów

Legal Bookmakers Award 2019

Best Mobile App

Mobile Trends Awards logo

Mobile Trends Awards 2023

Winning app in MCOMMERCE DEVELOPMENT

23

client reviews

Clutch logo