小编one*_*uan的帖子

SwiftUI 通用链接不适用于 NFC

我们的应用程序使用通用链接,并且 AASA 文件似乎工作正常,因为电子邮件中的超链接以及 QR 编码 URL 都会启动该应用程序。它们还会导致.onOpenURL(perform:)调用 SwiftUI 函数。

NFC 的情况有点令人困惑。URL 被识别并且应用程序启动,表明该问题与 AASA 无关。但是,该onOpenURL函数未被调用。谁能告诉我如何处理 NFC 的通用链接?理想情况下,我希望保持纯粹的 SwiftUI,但如果我需要使用 AppDelegate 就这样吧。

主 SwiftUI 文件中的代码是:

import SwiftUI

@main
struct MyApp: App {
    
    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
    
    var body: some Scene {
            WindowGroup {
                ContentView()
                    .onOpenURL(perform: { url in
                        print("url opened:\(url)")
                        // prints when opened from URL in email, 
                        // Notes or QR code, but not when opened 
                        // from URL embedded in NFC NDEF
                    })
            }
        
    }
}
Run Code Online (Sandbox Code Playgroud)

我还尝试application(_:continue:restorationHandler:) …

nfc swift swiftui

3
推荐指数
1
解决办法
994
查看次数

使用 Swift Codable 解码 firestore 文档时获取文档 ID

我正在使用一个类来解码检索到的 firestore 文档,如果我不想操作数据,它会按预期工作:

class Room: Identifiable, Codable {

    @DocumentID public var id:String?
    var name:String

}
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试使用自己的 init 来设置值,我无法获取 firestore 文档 ID?

class Room: Identifiable, Codable {

    @DocumentID public var id:String?
    var name:String
    
    
    enum Keys:String, CodingKey {
        case name
        case capacity
        case photo = "url"
    }
    
    required init(from decoder: Decoder) throws {

        // How do I get the document ID to set the id value?

        let container = try decoder.container(keyedBy: Keys.self)
        name = try container.decode(String.self, forKey: .name)
        capacity = try container.decode(Int.self, …
Run Code Online (Sandbox Code Playgroud)

ios swift codable google-cloud-firestore

3
推荐指数
1
解决办法
927
查看次数

标签 统计

swift ×2

codable ×1

google-cloud-firestore ×1

ios ×1

nfc ×1

swiftui ×1