diff --git a/RadioSpiral.xcodeproj/project.pbxproj b/RadioSpiral.xcodeproj/project.pbxproj index 14d34cfa..090475b7 100644 --- a/RadioSpiral.xcodeproj/project.pbxproj +++ b/RadioSpiral.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 5FDEE0221F72FF980064333C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 5FDEE0211F72FF980064333C /* LaunchScreen.storyboard */; }; 6258DCD822D93A3500166C65 /* LogoShareView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6258DCD722D93A3500166C65 /* LogoShareView.swift */; }; 6258DCDA22D93A5400166C65 /* LogoShareView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6258DCD922D93A5400166C65 /* LogoShareView.xib */; }; + 710189282B366D3300E8A04C /* RadioAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710189272B366D3300E8A04C /* RadioAPI.swift */; }; 715C87A62B23E141003FC57A /* SnapshotHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 715C87A52B23E141003FC57A /* SnapshotHelper.swift */; }; 7165121C2B35519B00473770 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CF72ACE621F714D000461EED /* Main.storyboard */; }; 9409E11C1ABF6FEA00312E2B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9409E11B1ABF6FEA00312E2B /* AppDelegate.swift */; }; @@ -106,6 +107,7 @@ 5FDEE0211F72FF980064333C /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 6258DCD722D93A3500166C65 /* LogoShareView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoShareView.swift; sourceTree = ""; }; 6258DCD922D93A5400166C65 /* LogoShareView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LogoShareView.xib; sourceTree = ""; }; + 710189272B366D3300E8A04C /* RadioAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioAPI.swift; sourceTree = ""; }; 715C87A52B23E141003FC57A /* SnapshotHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SnapshotHelper.swift; path = fastlane/SnapshotHelper.swift; sourceTree = SOURCE_ROOT; }; 9409E1161ABF6FEA00312E2B /* RadioSpiral.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RadioSpiral.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9409E11A1ABF6FEA00312E2B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -287,6 +289,7 @@ children = ( 94AC70AD1AD05C6200652982 /* RadioStation.swift */, CE963ECB29135A6F004F299E /* StationsManager.swift */, + 710189272B366D3300E8A04C /* RadioAPI.swift */, ); path = Model; sourceTree = ""; @@ -398,7 +401,7 @@ BuildIndependentTargetsInParallel = YES; LastSwiftMigration = 0700; LastSwiftUpdateCheck = 0710; - LastUpgradeCheck = 1500; + LastUpgradeCheck = 1510; ORGANIZATIONNAME = matthewfecher.com; TargetAttributes = { 2C5545B91C1124DE00728469 = { @@ -497,6 +500,7 @@ CE6036192A48BA2500E15E15 /* UITableViewCell+reuseIdentifier.swift in Sources */, CE6036162A47B88600E15E15 /* StationTableViewCell.swift in Sources */, CE9EE8DE293BB41300F62041 /* BaseController.swift in Sources */, + 710189282B366D3300E8A04C /* RadioAPI.swift in Sources */, 53113F39230C720900462C0E /* ShareActivity.swift in Sources */, 9409E1401ABF78B000312E2B /* NowPlayingViewController.swift in Sources */, CE963ECC29135A6F004F299E /* StationsManager.swift in Sources */, diff --git a/RadioSpiral.xcodeproj/xcshareddata/xcschemes/RadioSpiral-CarPlay.xcscheme b/RadioSpiral.xcodeproj/xcshareddata/xcschemes/RadioSpiral-CarPlay.xcscheme index d909ea25..e5dde5df 100644 --- a/RadioSpiral.xcodeproj/xcshareddata/xcschemes/RadioSpiral-CarPlay.xcscheme +++ b/RadioSpiral.xcodeproj/xcshareddata/xcschemes/RadioSpiral-CarPlay.xcscheme @@ -1,6 +1,6 @@ ) -> Void) { + + // Create a data task to make the HTTP request + let task = URLSession.shared.dataTask(with: endpointURL) { (data, response, error) in + // Check for errors + if let error = error { + completion(.failure(error)) + return + } + + // Check for a valid HTTP response + guard let httpResponse = response as? HTTPURLResponse, (200...299).contains(httpResponse.statusCode) else { + completion(.failure(NSError(domain: "Invalid HTTP response", code: 0, userInfo: nil))) + return + } + + // Check for valid data + guard let data = data else { + completion(.failure(NSError(domain: "No data received", code: 0, userInfo: nil))) + return + } + + result = String(decoding: data, as: UTF8.self) + do { + // Decode the JSON response + let decoder = JSONDecoder() + let broadcastResponse = try decoder.decode(BroadcastResponse.self, from: data) + + // Extract and pass the current show value to the completion handler + completion(.success(broadcastResponse.current_show)) + } catch { + // Handle decoding errors within the closure + completion(.failure(error)) + } + } + + // Start the data task + task.resume() + } +} diff --git a/RadioSpiral/ViewControllers/NowPlayingViewController.swift b/RadioSpiral/ViewControllers/NowPlayingViewController.swift index 5ce844cc..c6ad8317 100644 --- a/RadioSpiral/ViewControllers/NowPlayingViewController.swift +++ b/RadioSpiral/ViewControllers/NowPlayingViewController.swift @@ -244,6 +244,16 @@ class NowPlayingViewController: UIViewController { } else { playingLive.text = "" } + RadioAPI.getCurrentDJ { result in + DispatchQueue.main.async { + switch result { + case .success(let currentDJ): + self.djName.text = currentDJ + case .failure(_): + self.djName.text = "Spud the Ambient Robot" + } + } + } shouldAnimateSongLabel(animate) return }