forked from analogcode/Swift-Radio-Pro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
53 additions
and
36 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
File renamed without changes.
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,43 @@ | ||
// | ||
// Handoffable.swift | ||
// SwiftRadio | ||
// | ||
// Created by Fethi El Hassasna on 2022-11-24. | ||
// Copyright © 2022 matthewfecher.com. All rights reserved. | ||
// | ||
|
||
import UIKit | ||
import FRadioPlayer | ||
|
||
protocol Handoffable: UIResponder {} | ||
|
||
extension Handoffable { | ||
|
||
func setupHandoffUserActivity() { | ||
userActivity = NSUserActivity(activityType: NSUserActivityTypeBrowsingWeb) | ||
userActivity?.becomeCurrent() | ||
} | ||
|
||
func updateHandoffUserActivity(_ activity: NSUserActivity?, station: RadioStation?) { | ||
guard let activity = activity else { return } | ||
|
||
defer { updateUserActivityState(activity) } | ||
|
||
guard let metadata = FRadioPlayer.shared.currentMetadata, let artistName = metadata.artistName, let trackName = metadata.trackName else { | ||
activity.webpageURL = nil | ||
return | ||
} | ||
|
||
activity.webpageURL = getHandoffURL(artistName: artistName, trackName: trackName) | ||
} | ||
|
||
private func getHandoffURL(artistName: String, trackName: String) -> URL? { | ||
var components = URLComponents() | ||
components.scheme = "https" | ||
components.host = "google.com" | ||
components.path = "/search" | ||
components.queryItems = [URLQueryItem]() | ||
components.queryItems?.append(URLQueryItem(name: "q", value: "\(artistName) \(trackName)")) | ||
return components.url | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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