-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ios: allow example app users to configure API URL and key (#87)
- Loading branch information
1 parent
4dbd21a
commit d2f5dd9
Showing
5 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// capture-sdk - bitdrift's client SDK | ||
// Copyright Bitdrift, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by a source available license that can be found in the | ||
// LICENSE file or at: | ||
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt | ||
|
||
import Combine | ||
import Foundation | ||
|
||
final class Configuration: ObservableObject { | ||
@Published var apiURL: String | ||
@Published var apiKey: String | ||
|
||
private var subscriptions = Set<AnyCancellable>() | ||
|
||
static var storedAPIURL: String { | ||
get { UserDefaults.standard.string(forKey: "apiURL") ?? "https://api.bitdrift.io" } | ||
set { UserDefaults.standard.setValue(newValue, forKey: "apiURL") } | ||
} | ||
|
||
static var storedAPIKey: String? { | ||
get { UserDefaults.standard.string(forKey: "apiKey") } | ||
set { UserDefaults.standard.setValue(newValue, forKey: "apiKey") } | ||
} | ||
|
||
init() { | ||
self.apiURL = Self.storedAPIURL | ||
self.apiKey = Self.storedAPIKey ?? "" | ||
|
||
$apiURL | ||
.sink(receiveValue: { Self.storedAPIURL = $0 }) | ||
.store(in: &self.subscriptions) | ||
$apiKey | ||
.sink(receiveValue: { Self.storedAPIKey = $0 }) | ||
.store(in: &self.subscriptions) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// capture-sdk - bitdrift's client SDK | ||
// Copyright Bitdrift, Inc. All rights reserved. | ||
// | ||
// Use of this source code is governed by a source available license that can be found in the | ||
// LICENSE file or at: | ||
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt | ||
|
||
import SwiftUI | ||
|
||
struct ConfigurationView: View { | ||
@StateObject var configuration = Configuration() | ||
|
||
var body: some View { | ||
Text("API URL").frame(maxWidth: .infinity) | ||
TextField(text: $configuration.apiURL) { Text("Enter API URL") } | ||
.autocapitalization(.none) | ||
|
||
Text("API Key").frame(maxWidth: .infinity) | ||
TextField(text: $configuration.apiKey, axis: .vertical) { Text("Enter API Key") } | ||
.autocapitalization(.none) | ||
|
||
Spacer() | ||
|
||
Text("The app needs to be restarted for any configuration change to take effect.") | ||
.font(.caption2) | ||
.padding(EdgeInsets(top: 10, leading: 10, bottom: 20, trailing: 10)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters