Skip to content

Commit 9118a3a

Browse files
[MINI-5899][iOS Sample] Enable deeplink/QR code to save the Project key and subscription key (#527)
* [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Enable passing the Project ID and subscription key using deep link. For eg., miniappdemo://miniapp/settings?projectid=abc&subscription=def **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) * [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix issue of keys not changing when switching List1-List2 in settings screen. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) * [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix swiftlint violations. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) * [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix issues identified by QA. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) * [MINI-5899] [iOS] - Enable deeplinking to Save Project keys using QR Fix swiftlint violations. **LINK** [MINI-5899](https://jira.rakuten-it.com/jira/browse/MINI-5899) * Update Example/Controllers/SwiftUI/MiniAppDashboardView.swift Commit for suggested changes. Co-authored-by: leojoseph.r <[email protected]> --------- Co-authored-by: leojoseph.r <[email protected]>
1 parent 0ccf59a commit 9118a3a

File tree

2 files changed

+44
-44
lines changed

2 files changed

+44
-44
lines changed

Example/Controllers/SwiftUI/MiniAppDashboardView.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class MiniAppDashboardViewModel: ObservableObject {
88

99
struct MiniAppDashboardView: View {
1010

11+
let deepLinkManager = DeeplinkManager()
12+
1113
@StateObject var viewModel = MiniAppDashboardViewModel()
1214
@StateObject var sharedSettingsVM: MiniAppSettingsViewModel
1315

@@ -76,6 +78,16 @@ struct MiniAppDashboardView: View {
7678
selection = 3
7779
}
7880
}
81+
.onOpenURL { url in
82+
let receivedDeepLink = deepLinkManager.manage(url: url)
83+
switch receivedDeepLink {
84+
case .unknown, .qrcode, .deeplink:
85+
return
86+
case let .settings(settinsInfo):
87+
prepareSettingsViewModel(with: settinsInfo)
88+
selection = 3
89+
}
90+
}
7991
}
8092

8193
var navigationTitle: String {
@@ -92,6 +104,35 @@ struct MiniAppDashboardView: View {
92104
return "Unknown"
93105
}
94106
}
107+
108+
func prepareSettingsViewModel(with params: SettingsParams) {
109+
if params.tab == 1 {
110+
let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI))
111+
sharedSettingsVM.listConfigI = list1
112+
} else {
113+
let list2 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listII))
114+
sharedSettingsVM.listConfigII = list2
115+
}
116+
sharedSettingsVM.selectedListConfig = params.tab == 1 ? .listI : .listII
117+
}
118+
119+
func setConfigValues(with params: SettingsParams, for listConfig: ListConfiguration) -> ListConfiguration {
120+
var listConfig = listConfig
121+
listConfig.listType = params.tab == 1 ? .listI : .listII
122+
if params.isProduction {
123+
listConfig.environmentMode = .production
124+
} else {
125+
listConfig.environmentMode = .staging
126+
}
127+
if params.isPreviewMode {
128+
listConfig.previewMode = .previewable
129+
} else {
130+
listConfig.previewMode = .published
131+
}
132+
listConfig.projectId = params.projectId
133+
listConfig.subscriptionKey = params.subscriptionKey
134+
return listConfig
135+
}
95136
}
96137

97138
struct MiniAppDashboardView_Previews: PreviewProvider {

Example/SampleApp.swift

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ struct SampleApp: App {
4141
print(error)
4242
}
4343
}
44-
case let .settings(settinsInfo):
45-
prepareSettingsViewModel(with: settinsInfo)
46-
deepLink = .settings(viewModel: self.sharedSettingsViewModel)
44+
case let .settings(_):
45+
return
4746
}
4847
}
4948
.sheet(item: $deepLink) {
@@ -61,52 +60,12 @@ struct SampleApp: App {
6160
}
6261
.accentColor(.red)
6362
case .settings(let viewModel):
64-
NavigationView {
65-
MiniAppSettingsView(viewModel: viewModel, showFullProgress: .constant(false))
66-
}
63+
MiniAppDashboardView(sharedSettingsVM: viewModel, selection: 3)
6764
.accentColor(.red)
6865
}
6966
}
7067
}
7168
}
72-
73-
func prepareSettingsViewModel(with params: SettingsParams) {
74-
if params.tab == 1 {
75-
let list1 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listI))
76-
sharedSettingsViewModel.listConfig = list1
77-
sharedSettingsViewModel.listConfigI = list1
78-
sharedSettingsViewModel.listConfigI.persist()
79-
} else {
80-
let list2 = self.setConfigValues(with: params, for: ListConfiguration(listType: .listII))
81-
sharedSettingsViewModel.listConfig = list2
82-
sharedSettingsViewModel.listConfigII = list2
83-
sharedSettingsViewModel.listConfigII.persist()
84-
}
85-
sharedSettingsViewModel.listConfig.persist()
86-
sharedSettingsViewModel.selectedListConfig = params.tab == 1 ? .listI : .listII
87-
}
88-
89-
func setConfigValues(with params: SettingsParams, for listConfig: ListConfiguration) -> ListConfiguration {
90-
var listConfig = listConfig
91-
if params.isProduction {
92-
listConfig.environmentMode = .production
93-
listConfig.projectIdProd = params.projectId
94-
listConfig.subscriptionKey = params.subscriptionKey
95-
} else {
96-
listConfig.environmentMode = .staging
97-
listConfig.projectIdStaging = params.projectId
98-
listConfig.subscriptionKeyStaging = params.subscriptionKey
99-
}
100-
if params.isPreviewMode {
101-
listConfig.previewMode = .previewable
102-
} else {
103-
listConfig.previewMode = .published
104-
}
105-
listConfig.projectId = params.projectId
106-
listConfig.subscriptionKey = params.subscriptionKey
107-
listConfig.persist()
108-
return listConfig
109-
}
11069
}
11170

11271
enum SampleAppDeeplink: Identifiable {

0 commit comments

Comments
 (0)