Skip to content

Commit ff360a4

Browse files
committed
Dispatch an action to open the application settings
1 parent 65af33a commit ff360a4

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

Authenticator/Source/AppController.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ class AppController {
182182
feedbackGenerator.notificationOccurred(.success)
183183
}
184184

185+
case .showApplicationSettings:
186+
guard let applicationSettingsURL = URL(string: UIApplicationOpenSettingsURLString) else {
187+
handleEffect(.showErrorMessage("Failed to open application settings."))
188+
return
189+
}
190+
UIApplication.shared.openURL(applicationSettingsURL)
191+
185192
case let .openURL(url):
186193
if #available(iOS 9.0, *) {
187194
let safariViewController = SFSafariViewController(url: url)

Authenticator/Source/Root.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ extension Root {
119119

120120
case showErrorMessage(String)
121121
case showSuccessMessage(String)
122+
case showApplicationSettings
122123
case openURL(URL)
123124
}
124125

@@ -283,6 +284,9 @@ extension Root {
283284
modal = .entryForm(TokenEntryForm())
284285
return nil
285286

287+
case .showApplicationSettings:
288+
return .showApplicationSettings
289+
286290
case .saveNewToken(let token):
287291
return .addToken(token,
288292
success: Event.tokenFormSucceeded,

Authenticator/Source/TokenScanner.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ struct TokenScanner: Component {
5050
enum Action {
5151
case cancel
5252
case beginManualTokenEntry
53+
case showApplicationSettings
5354
case scannerDecodedText(String)
5455
case scannerError(Error)
5556
}
5657

5758
enum Effect {
5859
case cancel
5960
case beginManualTokenEntry
61+
case showApplicationSettings
6062
case saveNewToken(Token)
6163
case showErrorMessage(String)
6264
}
@@ -69,6 +71,9 @@ struct TokenScanner: Component {
6971
case .beginManualTokenEntry:
7072
return .beginManualTokenEntry
7173

74+
case .showApplicationSettings:
75+
return .showApplicationSettings
76+
7277
case .scannerDecodedText(let text):
7378
// Attempt to create a token from the decoded text
7479
guard let url = URL(string: text),

Authenticator/Source/TokenScannerViewController.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ class TokenScannerViewController: UIViewController, QRScannerDelegate {
174174
}
175175

176176
func editPermissions() {
177-
if let applicationSettingsURL = URL(string: UIApplicationOpenSettingsURLString) {
178-
UIApplication.shared.openURL(applicationSettingsURL)
179-
}
177+
dispatchAction(.showApplicationSettings)
180178
}
181179

182180
// MARK: QRScannerDelegate

0 commit comments

Comments
 (0)