From afca6f35565a0466fbec811db6fba62f60ca3f2a Mon Sep 17 00:00:00 2001 From: sosloan Date: Wed, 22 Jan 2025 04:13:36 -0800 Subject: [PATCH] Add sandbox API call in StudyHallOrgApp Add functionality to call a sandbox API from the Swift app. * **StudyHallOrgApp.swift** * Import `Foundation` module. * Add `callSandboxAPI()` function call in `StudyHallOrgApp`'s `body` within the `.onAppear` modifier. * **ContentView.swift** * Add a button to call `callSandboxAPI()` in the `NavigationSplitView` toolbar. * **Info.plist** * Add `NSAppTransportSecurity` key with `NSAllowsArbitraryLoads` set to `true`. --- StudyHallOrg/ContentView.swift | 12 +++++------- StudyHallOrg/Info.plist | 6 +++++- StudyHallOrg/StudyHallOrgApp.swift | 11 ++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/StudyHallOrg/ContentView.swift b/StudyHallOrg/ContentView.swift index 918f848..15a7935 100644 --- a/StudyHallOrg/ContentView.swift +++ b/StudyHallOrg/ContentView.swift @@ -1,10 +1,3 @@ -// -// ContentView.swift -// StudyHallOrg -// -// Created by Steve Sloan on 9/21/24. -// - import SwiftUI import SwiftData @@ -33,6 +26,11 @@ struct ContentView: View { Label("Add Item", systemImage: "plus") } } + ToolbarItem { + Button(action: callSandboxAPI) { + Label("Call Sandbox API", systemImage: "network") + } + } } } detail: { Text("Select an item") diff --git a/StudyHallOrg/Info.plist b/StudyHallOrg/Info.plist index ca9a074..ee6c5df 100644 --- a/StudyHallOrg/Info.plist +++ b/StudyHallOrg/Info.plist @@ -6,5 +6,9 @@ remote-notification + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + - diff --git a/StudyHallOrg/StudyHallOrgApp.swift b/StudyHallOrg/StudyHallOrgApp.swift index 089a5c9..69e1dc1 100644 --- a/StudyHallOrg/StudyHallOrgApp.swift +++ b/StudyHallOrg/StudyHallOrgApp.swift @@ -1,12 +1,6 @@ -// -// StudyHallOrgApp.swift -// StudyHallOrg -// -// Created by Steve Sloan on 9/21/24. -// - import SwiftUI import SwiftData +import Foundation @main struct StudyHallOrgApp: App { @@ -28,5 +22,8 @@ struct StudyHallOrgApp: App { ContentView() } .modelContainer(sharedModelContainer) + .onAppear { + callSandboxAPI() + } } }