Scheduling Local Notification in iOS

Tri Rejeki
2 min readAug 12, 2019

--

Photo by Jamie Street on Unsplash

Introduction

Local notifications are short, text-based messages that appear at the top of your iPhone’s screen.

On iOS, you can send and receive two types of notifications:

  • Push Notifications: Push notifications are sent via the internet, such as chat messages. They’re relayed to your iPhone via the web-based Apple Push Notification Service (APNS).
  • Local Notifications: Local notifications are scheduled and “sent” locally on your iPhone, so they aren’t sent over the internet. Typical use cases are calendar reminders or the iPhone alarm clock.

Local notifications are ideal for “local” functionality, such as reminding a user about an upcoming calendar event, a pending to-do list item, or an inspiring quote from your favorite wellness app.

In this article i will share about this Local Notification and how to create it.

Setups Notification Permission

Let’s assume you already have an existing project.

Go to your AppDelegate.swift then add permission for your local notification.

Create Local Notification Helper

Create new class, let’s called NotificationHelper.swift. This class represent helper to create local notification schedule.

Inside this helper you can add necesarry function for Local Notification such as schedule creation and remove notification schedule. But before that, you need to create some model data to passing your schedule data into Local Notification.

Let say i’ll make schedule for muslim prayer time. I need to create schedule model data first.

After this model data created, it will be easy to passing into Local Notification Creation.

Now let’s get back to NotificationHelper.swift.

Add createLocalNotif function.

The main point of this function is this line:

this part will register your schedule into Local Notification.

Parsing from Model Data into Create Local Notification

This function can be called from you view controller to send JadwalModel data to registered as scheduled Local Notification.

Remove Local Notification

This function is to remove all your Local Notification.

How to register the Local Notification

To register your local notification just simply called.

NotificationHelper.manageLocalNotif(data: YourData)

Make sure YourData is an array of object from JadwalModel.

To remove your local notification just simply called.

NotificationHelper.removeLocalNotification()

That’s it for Local Notification and Good Luck.

Tri Rejeki is an iOS Developer. She has almost 10 years experience in the IT field on various roles such as Java Programmer and Android Developer.

--

--

Tri Rejeki
Tri Rejeki

Written by Tri Rejeki

iOS Developer & Mobile Development Enthusiast

Responses (1)