Skip to content

Commit c0e0121

Browse files
authored
Merge pull request #667 from Esri/Caleb/Fix-AuthenticationSwitchBug
[Fix] Sample teardown issues
2 parents d8740f0 + 41c9d38 commit c0e0121

File tree

46 files changed

+245
-77
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+245
-77
lines changed

Samples.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@
577577
D7AE861F2AC39E7F0049B626 /* DisplayAnnotationView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7AE861D2AC39DC50049B626 /* DisplayAnnotationView.swift */; };
578578
D7AE86202AC3A1050049B626 /* AddCustomDynamicEntityDataSourceView.Vessel.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = 7900C5F52A83FC3F002D430F /* AddCustomDynamicEntityDataSourceView.Vessel.swift */; };
579579
D7AE86212AC3A10A0049B626 /* GroupLayersTogetherView.GroupLayerListView.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D75C35662AB50338003CD55F /* GroupLayersTogetherView.GroupLayerListView.swift */; };
580+
D7AECFDD2E31448100FD312A /* View+OnTeardown.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7AECFDC2E31448100FD312A /* View+OnTeardown.swift */; };
580581
D7B759B32B1FFBE300017FDD /* FavoritesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7B759B22B1FFBE300017FDD /* FavoritesView.swift */; };
581582
D7BA38912BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7BA38902BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift */; };
582583
D7BA38922BFBC4F0009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift in Copy Source Code Files */ = {isa = PBXBuildFile; fileRef = D7BA38902BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift */; };
@@ -1342,6 +1343,7 @@
13421343
D7ABA2F82A32579C0021822B /* MeasureDistanceInSceneView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MeasureDistanceInSceneView.swift; sourceTree = "<group>"; };
13431344
D7ABA2FE2A32881C0021822B /* ShowViewshedFromGeoelementInSceneView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShowViewshedFromGeoelementInSceneView.swift; sourceTree = "<group>"; };
13441345
D7AE861D2AC39DC50049B626 /* DisplayAnnotationView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisplayAnnotationView.swift; sourceTree = "<group>"; };
1346+
D7AECFDC2E31448100FD312A /* View+OnTeardown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+OnTeardown.swift"; sourceTree = "<group>"; };
13451347
D7B759B22B1FFBE300017FDD /* FavoritesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesView.swift; sourceTree = "<group>"; };
13461348
D7BA38902BFBC476009954F5 /* EditFeaturesWithFeatureLinkedAnnotationView.Model.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EditFeaturesWithFeatureLinkedAnnotationView.Model.swift; sourceTree = "<group>"; };
13471349
D7BA38932BFBFC0F009954F5 /* QueryRelatedFeaturesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QueryRelatedFeaturesView.swift; sourceTree = "<group>"; };
@@ -1464,6 +1466,7 @@
14641466
D7A670D42DADB9630060E327 /* Bundle.swift */,
14651467
D7A670D62DADBC770060E327 /* EnvironmentValues+RequestReviewModel.swift */,
14661468
00181B452846AD7100654571 /* View+ErrorAlert.swift */,
1469+
D7AECFDC2E31448100FD312A /* View+OnTeardown.swift */,
14671470
D7142BC32DB71082004F87B7 /* View+PagePresentation.swift */,
14681471
);
14691472
path = Extensions;
@@ -4649,6 +4652,7 @@
46494652
00A7A14A2A2FC5B700F035F7 /* DisplayContentOfUtilityNetworkContainerView.Model.swift in Sources */,
46504653
E004A6F0284E4B9B002A1FE6 /* DownloadVectorTilesToLocalCacheView.swift in Sources */,
46514654
00ABA94E2BF6721700C0488C /* ShowGridView.swift in Sources */,
4655+
D7AECFDD2E31448100FD312A /* View+OnTeardown.swift in Sources */,
46524656
1CAB8D4E2A3CEAB0002AA649 /* RunValveIsolationTraceView.swift in Sources */,
46534657
D7A737E02BABB9FE00B7C7FC /* AugmentRealityToShowHiddenInfrastructureView.swift in Sources */,
46544658
4D2ADC4329C26D05003B367F /* AddDynamicEntityLayerView.swift in Sources */,

Scripts/GenerateSampleViewSourceCode.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ private struct SampleMetadata: Decodable {
4343
let keywords: [String]
4444
/// The relevant APIs of the sample.
4545
let relevantApis: [String]
46+
/// A Boolean value indicating whether a sample has an action that needs to
47+
/// be performed when its view disappears.
48+
let hasTeardown: Bool? // swiftlint:disable:this discouraged_optional_boolean
4649
}
4750

4851
extension SampleMetadata {
@@ -130,6 +133,7 @@ private let sampleStructs = sampleMetadata
130133
var snippets: [String] { \(sample.snippets) }
131134
var tags: Set<String> { \(sample.tags) }
132135
\(portalItemIDs.isEmpty ? "" : "var hasDependencies: Bool { true }\n")
136+
var hasTeardown: Bool { \(sample.hasTeardown ?? false) }
133137
func makeBody() -> AnyView { .init(\(sample.viewName)()) }
134138
}
135139
"""

Shared/Samples/Add feature layers/AddFeatureLayersView.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ struct AddFeatureLayersView: View {
5353
// specified credentials and tokens for any challenges.
5454
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler = ChallengeHandler()
5555
}
56-
.onDisappear {
57-
// Resets the URL session challenge handler to use default handling.
56+
.onTeardown {
57+
// Resets the URL session challenge handler to use default handling
58+
// and removes all credentials.
5859
ArcGISEnvironment.authenticationManager.arcGISAuthenticationChallengeHandler = nil
60+
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.removeAll()
5961
}
6062
}
6163
}

Shared/Samples/Add feature layers/README.metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"category": "Layers",
33
"description": "Display feature layers from various data sources.",
4+
"has_teardown": true,
45
"ignore": false,
56
"images": [
67
"add-feature-layers.png"

Shared/Samples/Add items to portal/AddItemsToPortalView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ struct AddItemsToPortalView: View {
9292
apiKey = ArcGISEnvironment.apiKey
9393
ArcGISEnvironment.apiKey = nil
9494
}
95-
.onDisappear {
95+
.onTeardown {
9696
// Resetting the challenge handlers and clearing credentials here in
9797
// `onDisappear` so user is prompted to enter credentials every time
9898
// trying the sample. In real world applications, do these from
@@ -103,7 +103,7 @@ struct AddItemsToPortalView: View {
103103

104104
// Sets the API key back to the original value.
105105
ArcGISEnvironment.apiKey = apiKey
106-
Task { await signOut() }
106+
await signOut()
107107
}
108108
}
109109

Shared/Samples/Add items to portal/README.metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"category": "Cloud and Portal",
33
"description": "This sample demonstrates how to add and delete items in a user's portal.",
4+
"has_teardown": true,
45
"ignore": false,
56
"images": [
67
"add-items-to-portal.png"

Shared/Samples/Analyze network with subnetwork trace/AnalyzeNetworkWithSubnetworkTraceView.Model.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ extension AnalyzeNetworkWithSubnetworkTraceView {
6262
/// A Boolean value indicating if the sample has been setup.
6363
@Published private(set) var isSetUp = false
6464

65-
deinit {
66-
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.removeAll()
67-
}
68-
6965
// MARK: Methods
7066

7167
/// Performs important tasks including adding credentials, loading utility network and setting trace parameters.
@@ -78,6 +74,11 @@ extension AnalyzeNetworkWithSubnetworkTraceView {
7874
}
7975
}
8076

77+
/// Cleans up the model's setup.
78+
func tearDown() {
79+
ArcGISEnvironment.authenticationManager.arcGISCredentialStore.removeAll()
80+
}
81+
8182
/// Loads the utility network and sets the trace parameters and other information
8283
/// used for running this sample.
8384
private func setupTraceParameters() async throws {

Shared/Samples/Analyze network with subnetwork trace/AnalyzeNetworkWithSubnetworkTraceView.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ struct AnalyzeNetworkWithSubnetworkTraceView: View {
9191
.toolbar {
9292
ToolbarItemGroup(placement: .bottomBar) { toolbarItems }
9393
}
94+
.onTeardown {
95+
model.tearDown()
96+
}
9497
}
9598
}
9699

Shared/Samples/Analyze network with subnetwork trace/README.metadata.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"category": "Utility Networks",
33
"description": "Get a server-defined trace configuration for a given tier and modify its traversability scope, add new condition barriers, and control what is included in the subnetwork trace result.",
4+
"has_teardown": true,
45
"ignore": false,
56
"images": [
67
"analyze-network-with-subnetwork-trace.png"

Shared/Samples/Authenticate with Integrated Windows Authentication/AuthenticateWithIntegratedWindowsAuthenticationView.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,12 @@ struct AuthenticateWithIntegratedWindowsAuthenticationView: View {
4646
}
4747
}
4848
}
49-
.onDisappear {
50-
Task {
51-
// Reset the challenge handlers and clear credentials
52-
// when the view disappears so that user is prompted to enter
53-
// credentials every time the sample is run, and to clean
54-
// the environment for other samples.
55-
await model.teardownAuthenticator()
56-
}
49+
.onTeardown {
50+
// Reset the challenge handlers and clear credentials
51+
// when the view disappears so that user is prompted to enter
52+
// credentials every time the sample is run, and to clean
53+
// the environment for other samples.
54+
await model.teardownAuthenticator()
5755
}
5856
.sheet(item: $model.selectedItem) { selectedItem in
5957
NavigationStack {

0 commit comments

Comments
 (0)