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
348
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
969
Feb ’24
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.4k
Jun ’20
Can't Share Data Between Main App And Extension
Hello, I've recently added a widget extension to my app. But I've been having trouble sharing data between the two using UserDefaults. Code Shared Code var AppGroup: String {     "group.someGroup" } Main App UserDefaults(suiteName: AppGroup)!.setValue(data, forKey: "TimeLine") // sets the value for main app. Widget Extension let data = UserDefaults(suiteName: AppGroup)!.data(forKey: "TimeLine") // can't get the value in extension. App groups are turned on in both targets, but the data is not shared. Any ideas as to why this is happening would be appreciated. Thank you.
2
0
3.2k
Oct ’20