From 3037323dc0ad3b98c1aac0a5f1066f61143395fb Mon Sep 17 00:00:00 2001 From: Jon Staab Date: Fri, 27 Jun 2025 08:33:31 -0700 Subject: [PATCH] Add support for ios push notifications --- ios/App/App.xcodeproj/project.pbxproj | 4 ++++ ios/App/Flotilla Chat.entitlements | 8 ++++++++ src/app/commands.ts | 1 + src/app/components/SpaceQuickLinks.svelte | 4 +--- src/app/push.ts | 20 +++++++++++++++++--- 5 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 ios/App/Flotilla Chat.entitlements diff --git a/ios/App/App.xcodeproj/project.pbxproj b/ios/App/App.xcodeproj/project.pbxproj index ce898f7b..cf655950 100644 --- a/ios/App/App.xcodeproj/project.pbxproj +++ b/ios/App/App.xcodeproj/project.pbxproj @@ -18,6 +18,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 051414282E0CC28400BE0BC8 /* Flotilla Chat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Flotilla Chat.entitlements"; sourceTree = ""; }; 1F53EE54954731A2328CBC4B /* Pods-Flotilla Chat.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Flotilla Chat.release.xcconfig"; path = "Pods/Target Support Files/Pods-Flotilla Chat/Pods-Flotilla Chat.release.xcconfig"; sourceTree = ""; }; 2FAD9762203C412B000D30F8 /* config.xml */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = config.xml; sourceTree = ""; }; 50379B222058CBB4000EE86E /* capacitor.config.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = capacitor.config.json; sourceTree = ""; }; @@ -57,6 +58,7 @@ 504EC2FB1FED79650016851F = { isa = PBXGroup; children = ( + 051414282E0CC28400BE0BC8 /* Flotilla Chat.entitlements */, 504EC3061FED79650016851F /* App */, 504EC3051FED79650016851F /* Products */, 7F8756D8B27F46E3366F6CEA /* Pods */, @@ -349,6 +351,7 @@ baseConfigurationReference = 7B9FA71C362B734D9F965709 /* Pods-Flotilla Chat.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = "Flotilla Chat.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 13; @@ -374,6 +377,7 @@ baseConfigurationReference = 1F53EE54954731A2328CBC4B /* Pods-Flotilla Chat.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_ENTITLEMENTS = "Flotilla Chat.entitlements"; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 13; diff --git a/ios/App/Flotilla Chat.entitlements b/ios/App/Flotilla Chat.entitlements new file mode 100644 index 00000000..903def2a --- /dev/null +++ b/ios/App/Flotilla Chat.entitlements @@ -0,0 +1,8 @@ + + + + + aps-environment + development + + diff --git a/src/app/commands.ts b/src/app/commands.ts index 23e59357..df37f323 100644 --- a/src/app/commands.ts +++ b/src/app/commands.ts @@ -394,6 +394,7 @@ export type AlertParams = { } ios?: { device_token: string + bundle_identifier: string } android?: { device_token: string diff --git a/src/app/components/SpaceQuickLinks.svelte b/src/app/components/SpaceQuickLinks.svelte index d0d07c02..f3759d73 100644 --- a/src/app/components/SpaceQuickLinks.svelte +++ b/src/app/components/SpaceQuickLinks.svelte @@ -112,9 +112,7 @@ Chat {#if $notifications.has(chatPath)} -
+
{/if}
diff --git a/src/app/push.ts b/src/app/push.ts index 95f97c3d..59e938f8 100644 --- a/src/app/push.ts +++ b/src/app/push.ts @@ -2,7 +2,7 @@ import * as nip19 from "nostr-tools/nip19" import {Capacitor} from "@capacitor/core" import type {ActionPerformed, RegistrationError, Token} from "@capacitor/push-notifications" import {PushNotifications} from "@capacitor/push-notifications" -import {sleep, parseJson} from "@welshman/lib" +import {parseJson, poll} from "@welshman/lib" import {isSignedEvent} from "@welshman/util" import {goto} from "$app/navigation" import {VAPID_PUBLIC_KEY} from "@app/state" @@ -69,6 +69,11 @@ export const getWebPushInfo = async () => { } } +export type PushInfo = { + device_token: string + bundle_identifier?: string +} + export const getCapacitorPushInfo = async () => { let status = await PushNotifications.checkPermissions() @@ -92,13 +97,22 @@ export const getCapacitorPushInfo = async () => { }) await PushNotifications.register() - await sleep(100) + await poll({ + condition: () => Boolean(device_token), + signal: AbortSignal.timeout(5000), + }) if (!device_token) { throw new Error(error) } - return {device_token} + const info: PushInfo = {device_token} + + if (platform === "ios") { + info.bundle_identifier = "social.flotilla" + } + + return info } export const getPushInfo = (): Promise> => {