Skip to content

Commit

Permalink
Merge pull request #1222 from joreilly/stylianos/conference-deep-link…
Browse files Browse the repository at this point in the history
…-for-ios

Conference deep link for iOS
  • Loading branch information
joreilly authored Apr 16, 2024
2 parents c1f9d65 + 9500a8c commit 5371ca2
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
4 changes: 4 additions & 0 deletions iosApp/iosApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
1AF675CF28F1F20B00CC1C26 /* SessionListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionListView.swift; sourceTree = "<group>"; };
1AF675D128F1F21700CC1C26 /* SessionDetailsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SessionDetailsView.swift; sourceTree = "<group>"; };
2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = "<group>"; };
550D7BF32BB75551004D5D59 /* iosApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = iosApp.entitlements; sourceTree = "<group>"; };
7555FF7B242A565900829871 /* Confetti.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Confetti.app; sourceTree = BUILT_PRODUCTS_DIR; };
7555FF82242A565900829871 /* ConfettiApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfettiApp.swift; sourceTree = "<group>"; };
7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -225,6 +226,7 @@
7555FF7D242A565900829871 /* iosApp */ = {
isa = PBXGroup;
children = (
550D7BF32BB75551004D5D59 /* iosApp.entitlements */,
1A584D0F2B8277440047DDD2 /* Recommendations */,
1AC8AB652AD2997C0067704E /* Venue */,
1AF675CA28F1F0F300CC1C26 /* Speakers */,
Expand Down Expand Up @@ -752,6 +754,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = iosApp/iosApp.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.0.2;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
Expand Down Expand Up @@ -786,6 +789,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_ENTITLEMENTS = iosApp/iosApp.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1.0.2;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
Expand Down
22 changes: 18 additions & 4 deletions iosApp/iosApp/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@
import SwiftUI
import ConfettiKit

class AppDelegate : NSObject, UIApplicationDelegate {
class AppDelegate : NSObject, UIApplicationDelegate, ObservableObject {

let root: AppComponent
private var applicationLifecycle: ApplicationLifecycle
@Published var appComponent: AppComponent

override init() {
KoinKt.doInitKoin()

root = DefaultAppComponent(
componentContext: DefaultComponentContext(lifecycle: ApplicationLifecycle()),
applicationLifecycle = ApplicationLifecycle()
appComponent = DefaultAppComponent(
componentContext: DefaultComponentContext(lifecycle: applicationLifecycle),
onSignOut: {},
onSignIn: {},
isMultiPane: UIDevice.current.userInterfaceIdiom != UIUserInterfaceIdiom.phone,
initialConferenceId: nil
)
}

func onConferenceDeepLink(conferenceId: String) {
applicationLifecycle.destroy()
applicationLifecycle = ApplicationLifecycle()
appComponent = DefaultAppComponent(
componentContext: DefaultComponentContext(lifecycle: applicationLifecycle),
onSignOut: {},
onSignIn: {},
isMultiPane: UIDevice.current.userInterfaceIdiom != UIUserInterfaceIdiom.phone,
initialConferenceId: conferenceId
)
}
}
22 changes: 21 additions & 1 deletion iosApp/iosApp/iOSApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ struct iOSApp: App {

var body: some Scene {
WindowGroup {
ConfettiApp(appDelegate.root)
ConfettiIosApp(appDelegate: appDelegate)
.onOpenURL(perform: { url in
let pathComponents = url.pathComponents
if pathComponents.count != 3 { return }
if pathComponents[1] != "conference" { return }
let conferenceId = pathComponents[2]
for char in conferenceId {
if !char.isLetter && !char.isNumber { return }
}
appDelegate.onConferenceDeepLink(conferenceId: conferenceId)
})
}
.onChange(of: phase) { newPhase in
switch newPhase {
Expand All @@ -26,6 +36,16 @@ struct iOSApp: App {
}
}

struct ConfettiIosApp : View {
@ObservedObject
var appDelegate: AppDelegate


var body: some View {
ConfettiApp(appDelegate.appComponent)
}
}

func scheduleDataRefresh() {
let request = BGAppRefreshTaskRequest(identifier: "refreshData")
request.earliestBeginDate = .now.addingTimeInterval(24 * 3600)
Expand Down
10 changes: 10 additions & 0 deletions iosApp/iosApp/iosApp.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:confetti-app.dev</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ class DefaultAppComponent(
init {
coroutineScope.launch {
if (initialConferenceId != null) {
// todo, consider changing how conference theme colors are decided so that only knowing the conference
// ID is enough to also get the right color
repository.setConference(initialConferenceId, null)
showConference(conference = initialConferenceId, conferenceThemeColor = null)
selectAndNavigateToDeepLinkedConference(initialConferenceId)
} else {
val conference: String = repository.getConference()
if (conference == AppSettings.CONFERENCE_NOT_SET) {
Expand All @@ -81,6 +78,13 @@ class DefaultAppComponent(
}
}

private suspend fun selectAndNavigateToDeepLinkedConference(conferenceId: String) {
// todo, consider changing how conference theme colors are decided so that only knowing the conference
// ID is enough to also get the right color
repository.setConference(conference = conferenceId, conferenceThemeColor = null)
showConference(conference = conferenceId, conferenceThemeColor = null)
}

private fun onUserChanged(uid: String?) {
navigation.navigate { oldStack ->
oldStack.map { config ->
Expand Down

0 comments on commit 5371ca2

Please sign in to comment.