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

Bitrise Tests Made Easier: Update JIRA Issues with Build Number and Forget About Delays in QA Testing

When you trigger Bitrise build with changes and forget to tell QA specialists some essential information, there are two likely scenarios. You waste time waiting for the update from the tester, only you don’t know it’s never coming. Or you get so many questions about builds that you can’t keep up. Sounds familiar? If so, let us tell you about the JIRA issue update that keeps workflow in order.
Read 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

WebSockets on iOS – Real-time Communication That Doesn’t Slow Down the App

When you want to download data for the app, you probably use API RESTful interface. All it takes is to ask the server for the data and that's it! This method works well when the app doesn't need permanent access to new information. But what to do if the content has to be updated in real-time? A delay can make it impossible for the user to buy an item or make a sports bet, for example. But there’s a solution – WebSockets on iOS. Check out why you should implement them, and how to do it.
Read more

Project estimation

Check out how we use our knowledge in practice, and make your project with us.

Why choose us?

Logo Mobile Trends Awards

Mobile Trends Awards 2017

Nomination in
M-COMMERCE category

17

client reviews

Clutch logo
Logo Legalni bukmacherzy

Legal Bookmakers Award 2019

Best Mobile App

60+

projects in portfolio