fix(iOS): SMB URL detection — show alert guiding to Files app instead of trying to play. Add import UIKit.

This commit is contained in:
yumoqing 2026-07-04 18:00:44 +08:00
parent d01baed1c9
commit 592a23b02e

View File

@ -2,6 +2,8 @@ import SwiftUI
import AVFoundation
#if os(macOS)
import AppKit
#else
import UIKit
#endif
// MARK: -
@ -257,6 +259,20 @@ struct NetworkFileBrowserIOS: View {
@State private var manualURL = ""
@State private var showFileImporter = false
@State private var showSMBAlert = false
@State private var smbAlertURL = ""
private func openInFiles(url: URL) {
smbAlertURL = url.absoluteString
showSMBAlert = true
}
private func openFilesApp() {
// Files
if let filesURL = URL(string: "shareddocuments://") {
UIApplication.shared.open(filesURL)
}
}
var body: some View {
NavigationView {
@ -295,15 +311,22 @@ struct NetworkFileBrowserIOS: View {
.font(.headline)
HStack {
TextField("https://... or smb://...", text: $manualURL)
TextField("https://... 播放流地址", text: $manualURL)
.textFieldStyle(.roundedBorder)
.keyboardType(.URL)
.autocapitalization(.none)
.disableAutocorrection(true)
Button("Open") {
guard let url = URL(string: manualURL.trimmingCharacters(in: .whitespaces)),
!manualURL.trimmingCharacters(in: .whitespaces).isEmpty else { return }
let trimmed = manualURL.trimmingCharacters(in: .whitespaces)
guard !trimmed.isEmpty, let url = URL(string: trimmed) else { return }
// SMB/NFS Files
if url.scheme == "smb" || url.scheme == "nfs" {
openInFiles(url: url)
return
}
let name = url.lastPathComponent.isEmpty ? (url.host ?? "Stream") : url.lastPathComponent
bridge.addURL(manualURL)
isPresented = false
@ -327,6 +350,12 @@ struct NetworkFileBrowserIOS: View {
Button("Close") { isPresented = false }
}
}
.alert("SMB/NFS Share", isPresented: $showSMBAlert) {
Button("Open Files App") { openFilesApp() }
Button("Cancel", role: .cancel) {}
} message: {
Text("To access SMB/NFS shares on iPhone:\n\n1. Open the Files app\n2. Tap ⋯ → Connect to Server\n3. Enter: \(smbAlertURL)\n4. Login with your credentials\n\nThen come back and use 'Browse Files'.")
}
.fileImporter(
isPresented: $showFileImporter,
allowedContentTypes: [.movie, .video, .audio, .mpeg4Movie, .quickTimeMovie, .mp3, .wav, .mpeg4Audio],