Demo.swift
ContentView.swift
App.swift
import Foundation
func startDownload() {
let url = URL(string: "https://example.com/large.zip")!
BGSession.shared.session.downloadTask(with: url).resume()
}
func startUpload(file: URL) {
var req = URLRequest(url: URL(string: "https://example.com/upload")!)
req.httpMethod = "POST"
BGSession.shared.session.uploadTask(with: req, fromFile: file).resume()
}
import SwiftUI
import Foundation
struct ContentView: View {
var body: some View {
VStack(spacing: 12) {
Button("Start Download") { startDownload() }
Button("Start Upload") {
let tmp = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("upload.bin")
try? Data(repeating: 0, count: 8).write(to: tmp)
startUpload(file: tmp)
}
}
.padding()
}
}
import SwiftUI
@main
struct MyApp: App {
var body: some Scene {
WindowGroup { ContentView() }
}
}