Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MINI-5899][iOS Sample] Enable deeplink/QR code to save the Project key and subscription key #527

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions Example/Controllers/SwiftUI/MiniAppDashboardView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class MiniAppDashboardViewModel: ObservableObject {

struct MiniAppDashboardView: View {

let deepLinkManager = DeeplinkManager()

@StateObject var viewModel = MiniAppDashboardViewModel()
@StateObject var sharedSettingsVM: MiniAppSettingsViewModel

Expand Down Expand Up @@ -76,6 +78,20 @@ struct MiniAppDashboardView: View {
selection = 3
}
}
.onOpenURL { url in
let receivedDeepLink = deepLinkManager.manage(url: url)
switch receivedDeepLink {
case .unknown:
return
case .qrcode:
return
case .deeplink:
return
case let .settings(settinsInfo):
prepareSettingsViewModel(with: settinsInfo)
selection = 3
}
GondiTilak marked this conversation as resolved.
Show resolved Hide resolved
}
}

var navigationTitle: String {
Expand All @@ -92,6 +108,35 @@ struct MiniAppDashboardView: View {
return "Unknown"
}
}

func prepareSettingsViewModel(with params: SettingsParams) {
if params.tab == 1 {
let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI))
sharedSettingsVM.listConfigI = list1
} else {
let list2 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listII))
sharedSettingsVM.listConfigII = list2
}
sharedSettingsVM.selectedListConfig = params.tab == 1 ? .listI : .listII
}

func setConfigValues(with params: SettingsParams, for listConfig: ListConfiguration) -> ListConfiguration {
var listConfig = listConfig
listConfig.listType = params.tab == 1 ? .listI : .listII
if params.isProduction {
listConfig.environmentMode = .production
} else {
listConfig.environmentMode = .staging
}
if params.isPreviewMode {
listConfig.previewMode = .previewable
} else {
listConfig.previewMode = .published
}
listConfig.projectId = params.projectId
listConfig.subscriptionKey = params.subscriptionKey
return listConfig
}
}

struct MiniAppDashboardView_Previews: PreviewProvider {
Expand Down
47 changes: 3 additions & 44 deletions Example/SampleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ struct SampleApp: App {
print(error)
}
}
case let .settings(settinsInfo):
prepareSettingsViewModel(with: settinsInfo)
deepLink = .settings(viewModel: self.sharedSettingsViewModel)
case let .settings(_):
return
}
}
.sheet(item: $deepLink) {
Expand All @@ -61,52 +60,12 @@ struct SampleApp: App {
}
.accentColor(.red)
case .settings(let viewModel):
NavigationView {
MiniAppSettingsView(viewModel: viewModel, showFullProgress: .constant(false))
}
MiniAppDashboardView(sharedSettingsVM: viewModel, selection: 3)
.accentColor(.red)
}
}
}
}

func prepareSettingsViewModel(with params: SettingsParams) {
if params.tab == 1 {
let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI))
sharedSettingsViewModel.listConfig = list1
sharedSettingsViewModel.listConfigI = list1
sharedSettingsViewModel.listConfigI.persist()
} else {
let list2 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listII))
sharedSettingsViewModel.listConfig = list2
sharedSettingsViewModel.listConfigII = list2
sharedSettingsViewModel.listConfigII.persist()
}
sharedSettingsViewModel.listConfig.persist()
sharedSettingsViewModel.selectedListConfig = params.tab == 1 ? .listI : .listII
}

func setConfigValues(with params: SettingsParams, for listConfig: ListConfiguration) -> ListConfiguration {
var listConfig = listConfig
if params.isProduction {
listConfig.environmentMode = .production
listConfig.projectIdProd = params.projectId
listConfig.subscriptionKey = params.subscriptionKey
} else {
listConfig.environmentMode = .staging
listConfig.projectIdStaging = params.projectId
listConfig.subscriptionKeyStaging = params.subscriptionKey
}
if params.isPreviewMode {
listConfig.previewMode = .previewable
} else {
listConfig.previewMode = .published
}
listConfig.projectId = params.projectId
listConfig.subscriptionKey = params.subscriptionKey
listConfig.persist()
return listConfig
}
}

enum SampleAppDeeplink: Identifiable {
Expand Down
Loading