Sending Push Notifications to two Apple Watches paired to one iPhone

Photo by Michał Kubalczyk on Unsplash

The problem

  1. If you turn off your iPhone, Apple Watch is still able to receive iMessages
  2. Family setup in WatchOS 7 (which is only available on cellular models) sort of uses the same setup we would like to achieve
  3. On this Apple Developer page, Apple states:

Devices and Frameworks

  • iPhone 12 Pro Max, running iOS 14.3
  • Apple Watch S5, running WatchOS 7.2
  • Apple Watch SE, running WatchOS 7.2
  • Leaf, a templating framework to generate a little front end
  • Fluent, an ORM framework
  • SQLite, to store the push tokens from the Watch
  • Vapor-APNS, an extension for Vapor to send Push Notifications via APNs

Developing

Configuring middleware

app.views.use(.leaf)
app.databases.use(.sqlite(.memory), as: DatabaseID.sqlite)app.migrations.add(CreateDevice(), to: .sqlite)try app.autoMigrate().wait()
try app.configurePush()

Configuring push

Creating the Apple Watch app
let appleECP8PrivateKey ="""-----BEGIN PRIVATE KEY-----<KEY GOES HERE>-----END PRIVATE KEY-----"""

API endpoints

  • list, which returns a list of all registered devices
  • put, which saves the token to the in-memory database
  • sendTestPush, which sends a push notification based to a specified device
let apiRoutes = app.grouped("api")try apiRoutes.grouped("push").register(collection: DeviceController())

A simple webpage

Let's play!

Apple Watch 44mm Series 5 on the left and Apple Watch SE 40mm on the right.
The Id and the tokens are anonymized.
Sending notifications to your Apple Watches!

--

--

--

💼iOS Developer // 🇳🇱The Netherlands // 👨‍🎓Apple Developer Academy Alumnus

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A Gift From Us

iOS Automation With Appium Desktop for Real Devices/Simulators

Mirroring Iphone Screen on Fedora Linux with UxPlay

How to screen mirroring iPhone on Fedora Linux

Composing SwiftUI Navigation

Creating a Share Extension in NativeScript

SwiftUI Picker, Toggle, Slider and Stepper fully explained

How to Create an Apple Card Payment Dial — Part 4

The new game-changing feature to look out for in iOS14

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dennis Vermeulen

Dennis Vermeulen

💼iOS Developer // 🇳🇱The Netherlands // 👨‍🎓Apple Developer Academy Alumnus

More from Medium

Pencil Kit

Think in Swift and do old things in new ways

My iOS Wishlist

Conceptual logo for the latest Apple iPhone operating system, iOS 16

The Art of Path Animation in SwiftUI