fix(iOS): SMB URL detection — show alert guiding to Files app instead of trying to play. Add import UIKit.
This commit is contained in:
parent
d01baed1c9
commit
592a23b02e
@ -2,6 +2,8 @@ import SwiftUI
|
|||||||
import AVFoundation
|
import AVFoundation
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
import AppKit
|
import AppKit
|
||||||
|
#else
|
||||||
|
import UIKit
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// MARK: - 网络共享文件项
|
// MARK: - 网络共享文件项
|
||||||
@ -257,6 +259,20 @@ struct NetworkFileBrowserIOS: View {
|
|||||||
|
|
||||||
@State private var manualURL = ""
|
@State private var manualURL = ""
|
||||||
@State private var showFileImporter = false
|
@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 {
|
var body: some View {
|
||||||
NavigationView {
|
NavigationView {
|
||||||
@ -295,15 +311,22 @@ struct NetworkFileBrowserIOS: View {
|
|||||||
.font(.headline)
|
.font(.headline)
|
||||||
|
|
||||||
HStack {
|
HStack {
|
||||||
TextField("https://... or smb://...", text: $manualURL)
|
TextField("https://... 播放流地址", text: $manualURL)
|
||||||
.textFieldStyle(.roundedBorder)
|
.textFieldStyle(.roundedBorder)
|
||||||
.keyboardType(.URL)
|
.keyboardType(.URL)
|
||||||
.autocapitalization(.none)
|
.autocapitalization(.none)
|
||||||
.disableAutocorrection(true)
|
.disableAutocorrection(true)
|
||||||
|
|
||||||
Button("Open") {
|
Button("Open") {
|
||||||
guard let url = URL(string: manualURL.trimmingCharacters(in: .whitespaces)),
|
let trimmed = manualURL.trimmingCharacters(in: .whitespaces)
|
||||||
!manualURL.trimmingCharacters(in: .whitespaces).isEmpty else { return }
|
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
|
let name = url.lastPathComponent.isEmpty ? (url.host ?? "Stream") : url.lastPathComponent
|
||||||
bridge.addURL(manualURL)
|
bridge.addURL(manualURL)
|
||||||
isPresented = false
|
isPresented = false
|
||||||
@ -327,6 +350,12 @@ struct NetworkFileBrowserIOS: View {
|
|||||||
Button("Close") { isPresented = false }
|
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(
|
.fileImporter(
|
||||||
isPresented: $showFileImporter,
|
isPresented: $showFileImporter,
|
||||||
allowedContentTypes: [.movie, .video, .audio, .mpeg4Movie, .quickTimeMovie, .mp3, .wav, .mpeg4Audio],
|
allowedContentTypes: [.movie, .video, .audio, .mpeg4Movie, .quickTimeMovie, .mp3, .wav, .mpeg4Audio],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user