Post

Replies

Boosts

Views

Activity

Pop to root view when selected tab is tapped again for WebKit
Hello everyone! I have a WKWebView in my swiftui app and would like to enable to "pop root view when selected tab is tapped again" feature, but I have been unable to figure out how to implement this. Here's the basic code: class TabIdentifierModel:ObservableObject { @Published var tabSelection:TabIdentifier { willSet { if newValue == tabSelection { NotificationCenter.default.post(name: .popRootView, object: nil, userInfo: ["tab": newValue.rawValue]) } } } init() { tabSelection = .home } } struct ContentView: View { @AppStorage(AppStorageKeys.enableShorts) var enableShorts = true @StateObject var storeVM = StoreVM() @StateObject var downloadURLManager = DownloadURLManager.shared @State var downloadViewIsOpen = false // ...... @State var tabSelection = TabIdentifierModel() var body: some View { TabView(selection: $tabSelection.tabSelection) { // ...... WebViewWrapper(url: $libraryTabURL) .tabItem { Label { Text("Library") } icon: { Image(systemName: "folder.fill") } }.tag(TabIdentifier.library) // ...... } .environmentObject(tabSelection) } } Tapping on the tab again doesn't seem to set the value again thus the NotificationCenter.default.post is not sent and the web view is not reloaded. Help would be much appreciated! Thanks in advance!
0
0
523
Jun ’24
How to handle website requesting fullscreen in visionOS?
I am working on a native visionOS app. I'm running into a problem when websites request fullscreen. Sample code: import SwiftUI import WebKit struct WebViewWrapper: UIViewRepresentable { let url: String func makeUIView(context: Context) -> WKWebView { let webConfiguration = WKWebViewConfiguration() webConfiguration.allowsInlineMediaPlayback = false webConfiguration.mediaPlaybackRequiresUserAction = false let webView = WKWebView(frame: .zero, configuration: webConfiguration) webView.navigationDelegate = context.coordinator webView.uiDelegate = context.coordinator return webView } func updateUIView(_ uiView: WKWebView, context: Context) { if let url = URL(string: url) { let request = URLRequest(url: url) uiView.load(request) } } func makeCoordinator() -> Coordinator { Coordinator(self) } class Coordinator: NSObject, WKNavigationDelegate, WKUIDelegate { var parent: WebViewWrapper init(_ parent: WebViewWrapper) { self.parent = parent } func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { if navigationAction.targetFrame == nil { webView.load(navigationAction.request) } return nil } } } struct ContentView: View { var body: some View { GeometryReader { geo in VStack { WebViewWrapper(url: "https://youtube.com") .clipShape(RoundedRectangle(cornerSize: CGSize(width: geo.size.width/40, height: geo.size.height/40))) .padding() } } } } #Preview(windowStyle: .automatic) { ContentView() } The error I'm getting: -[AVPlayerViewController enterFullScreenAnimated:completionHandler:] failed with error Invalid call of -[AVPlayerViewController (0x153087600) _transitionToFullScreenAnimated:interactive:completionHandler:]! Any help would be greatly appreciated.
4
0
1.4k
Mar ’24
How to make sticky card like in Apple Music
Hello everyone! I am wondering how to make one of those cards that sticks to the bottom of my view in SwiftUI. An example of this is in Apple Music where the now playing item and controls stay at the bottom throughout the navigation movements. Thank you and hope you having a great WWDC!
1
0
832
Jun ’22
How do you combine two video files side-by-side for 3d as one movie?
I have a 3d camera app that I'm working on and I am wondering how to put the two videos side-by-side to save to Photos as one video using this delegate method: func fileOutput(_ output: AVCaptureFileOutput,                         didFinishRecordingTo outputFileURL: URL,                         from connections: [AVCaptureConnection],                         error: Error?) { Thank You!
2
0
2.7k
Jan ’22
Pop to root view when selected tab is tapped again for WebKit
Hello everyone! I have a WKWebView in my swiftui app and would like to enable to "pop root view when selected tab is tapped again" feature, but I have been unable to figure out how to implement this. Here's the basic code: class TabIdentifierModel:ObservableObject { @Published var tabSelection:TabIdentifier { willSet { if newValue == tabSelection { NotificationCenter.default.post(name: .popRootView, object: nil, userInfo: ["tab": newValue.rawValue]) } } } init() { tabSelection = .home } } struct ContentView: View { @AppStorage(AppStorageKeys.enableShorts) var enableShorts = true @StateObject var storeVM = StoreVM() @StateObject var downloadURLManager = DownloadURLManager.shared @State var downloadViewIsOpen = false // ...... @State var tabSelection = TabIdentifierModel() var body: some View { TabView(selection: $tabSelection.tabSelection) { // ...... WebViewWrapper(url: $libraryTabURL) .tabItem { Label { Text("Library") } icon: { Image(systemName: "folder.fill") } }.tag(TabIdentifier.library) // ...... } .environmentObject(tabSelection) } } Tapping on the tab again doesn't seem to set the value again thus the NotificationCenter.default.post is not sent and the web view is not reloaded. Help would be much appreciated! Thanks in advance!
Replies
0
Boosts
0
Views
523
Activity
Jun ’24
How to handle website requesting fullscreen in visionOS?
I am working on a native visionOS app. I'm running into a problem when websites request fullscreen. Sample code: import SwiftUI import WebKit struct WebViewWrapper: UIViewRepresentable { let url: String func makeUIView(context: Context) -> WKWebView { let webConfiguration = WKWebViewConfiguration() webConfiguration.allowsInlineMediaPlayback = false webConfiguration.mediaPlaybackRequiresUserAction = false let webView = WKWebView(frame: .zero, configuration: webConfiguration) webView.navigationDelegate = context.coordinator webView.uiDelegate = context.coordinator return webView } func updateUIView(_ uiView: WKWebView, context: Context) { if let url = URL(string: url) { let request = URLRequest(url: url) uiView.load(request) } } func makeCoordinator() -> Coordinator { Coordinator(self) } class Coordinator: NSObject, WKNavigationDelegate, WKUIDelegate { var parent: WebViewWrapper init(_ parent: WebViewWrapper) { self.parent = parent } func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { if navigationAction.targetFrame == nil { webView.load(navigationAction.request) } return nil } } } struct ContentView: View { var body: some View { GeometryReader { geo in VStack { WebViewWrapper(url: "https://youtube.com") .clipShape(RoundedRectangle(cornerSize: CGSize(width: geo.size.width/40, height: geo.size.height/40))) .padding() } } } } #Preview(windowStyle: .automatic) { ContentView() } The error I'm getting: -[AVPlayerViewController enterFullScreenAnimated:completionHandler:] failed with error Invalid call of -[AVPlayerViewController (0x153087600) _transitionToFullScreenAnimated:interactive:completionHandler:]! Any help would be greatly appreciated.
Replies
4
Boosts
0
Views
1.4k
Activity
Mar ’24
Notification of Media playback status Mac
Hello, I am working on a Mac app and I would like to be able to get notifications (NotificationCenter.default.addObserver.add... MPMusicPlayerControllerPlaybackStateDidChange) when media starts to play in other apps. Is this possible on Mac? Thanks in advance!
Replies
1
Boosts
0
Views
1.1k
Activity
Jan ’23
How to SharePlay songs with MusicKit
Hi all, I've seen a lot of documentation of SharePlay for AVFoundation, but I was wondering if it is possible to integrate SharePlay with MusicKit. Can it be done?
Replies
0
Boosts
0
Views
961
Activity
Dec ’22
How to make sticky card like in Apple Music
Hello everyone! I am wondering how to make one of those cards that sticks to the bottom of my view in SwiftUI. An example of this is in Apple Music where the now playing item and controls stay at the bottom throughout the navigation movements. Thank you and hope you having a great WWDC!
Replies
1
Boosts
0
Views
832
Activity
Jun ’22
How do you combine two video files side-by-side for 3d as one movie?
I have a 3d camera app that I'm working on and I am wondering how to put the two videos side-by-side to save to Photos as one video using this delegate method: func fileOutput(_ output: AVCaptureFileOutput,                         didFinishRecordingTo outputFileURL: URL,                         from connections: [AVCaptureConnection],                         error: Error?) { Thank You!
Replies
2
Boosts
0
Views
2.7k
Activity
Jan ’22