Skip to content

Push Notifications for iOS via Supabase

Latest
Compare
Choose a tag to compare
@jblanked jblanked released this 22 Jun 02:05
· 126 commits to main since this release

This uses Supabase and UserNotifications to show a notification when a new message is inserted into the messages table.

You will need to have a Supabase account and create a table called messages with a column called message.

You will also need to enable push notifications in your app via the Apple Developer Portal.

Within Supabase, you will need your Supabase URL and Supabase Key. You can find these in the API section of your Supabase project.

This code is currently for iOS only.

To use, add this in your start.swift

// top of start.swift
#if os(iOS)
import NotificationCenter
import SwiftUI
import UIKit
#endif

// in onFinishLaunching()
#if os(iOS)
@UIApplicationDelegateAdaptor(EasyAppDelegate.self) var appDelegate
#endif

Task
{
	// activate did finish launching
    await appDelegate.application(UIApplication.shared, didFinishLaunchingWithOptions: nil)
    
    let supabase = Easybase(supabaseURL: "YOUR-URL",supabaseKey: "YOUR_KEY")
    
    await supabase.subscribeToInserts(roomName: "general")
    
}