Member-only story

Notifications, the whole shebang II using only iOS

Mark Lucking
4 min readFeb 14, 2020

I should start this article with a disclaimer, it based on iOS 13, Swift 5 and Xcode 11.x. If you reading this and those numbers look dated, be forewarned.

I should also warn you that notifications, principally remote ones involve Apple’s infrastructure which means you will need an Apple Developers account to use them.

Now if you just got here, you should perhaps go back to part I, read it first; if not read on.

So local notifications are good, and have their uses. But I suspect that what most apps really need/want is remote notifications. These are notifications that are fired via a server or in maybe another iOS device.

How do they work. Firstly you need to get permission to show notifications, if your not sure how to; you need to read part I. The first step for remote notifications is to get the ID of the device your running on. You need this to tell Apple where it needs to send a remote notifications. You do do with this code.

You recall from part I we had an App we called Noob. Reopen it and add this method to the appDelegate.swift.

func application( _ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let tokenParts = deviceToken.map { data in String(format: "%02.2hhx", data) }
let token = tokenParts.joined()
print("Device Token: \n\(token)\n")
}

--

--

Mark Lucking
Mark Lucking

Written by Mark Lucking

Coding for 35+ years, enjoying using and learning Swift/iOS development. Writer @ Better Programming, @The StartUp, @Mac O’Clock, Level Up Coding & More

No responses yet