【问题标题】:Preview canvas for SwiftUI not working, can’t find application bundleSwiftUI 的预览画布不起作用,找不到应用程序包
【发布时间】:2021-03-03 04:44:22
【问题描述】:

我是 iOS 开发新手(做过 Flutter 和一些 react Native),我想开始制作 iOS 应用程序。

但是我在启动预览画布时遇到了问题。当我开始一个新项目时,构建在启动预览画布时完美完成,但加载一点后我收到此错误:“无法在 iPhone 11 Pro 上安装预览主机“IntervalTraining.app”:提供所需应用程序的有效路径捆绑”

我假设预览主机无法以某种方式找到应用程序,但奇怪的是,当我运行模拟器时,一切正常,并且应用程序安装在模拟器上..

我尝试过“清理构建文件夹”,但这不起作用。我试图擦除模拟器 iPhone 上的所有数据并再次将其重新安装在模拟器上,然后运行预览画布,但这也不起作用。我还尝试删除DerivedData 文件夹中的所有文件并多次创建新项目。我也试过用谷歌搜索这个问题,但我主要在苹果开发者论坛中找到我已经尝试过或不起作用的解决方案的问题。而且我发现的大多数问题似乎也与原生反应有关......

有没有人遇到过同样的问题?

编辑:我在 Catalina 10.15.6 上运行 XCode 12.2 和一个全新的 hello world 项目:

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Hello, world!")
            .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

生成的报告是这样的:

FailedToInstallAppError: Failed to install "IntervalTraining.app"

Could not install the preview host "IntervalTraining.app" on iPhone 11 Pro

agentBundle = com.andreasjohansson.IntervalTraining {
    url: file:///Users/andreas/Library/Developer/Xcode/DerivedData/IntervalTraining-awlguvqxylziguefdxawcmontfri/Build/Intermediates.noindex/Previews/IntervalTraining/Products/Debug-iphonesimulator/IntervalTraining.app
    version: 8468
    signingInformation: Code Signing {
        identifier: com.andreasjohansson.IntervalTraining
        hasGetTaskAllow: false
        isSandboxed: false
    }
}
udid = AD33D7B1-27B6-4028-BA10-CD2A289EB378
device = iPhone 11 Pro (AD33D7B1-27B6-4028-BA10-CD2A289EB378, iOS 14.2, Booted)

==================================

|  HumanReadableNSError: Failed to install the requested application
|  
|  Provide a valid path to the desired application bundle.
|  
|  NSPOSIXErrorDomain (2):
|  ==NSLocalizedFailureReason: An application bundle was not found at the provided path.
|  ==bundleURL: file:///Users/andreas/Library/Developer/Xcode/DerivedData/IntervalTraining-awlguvqxylziguefdxawcmontfri/Build/Intermediates.noindex/Previews/IntervalTraining/Products/Debug-iphonesimulator/IntervalTraining.app

【问题讨论】:

    标签: ios xcode swiftui


    【解决方案1】:

    我不知道这是否对你有帮助。

    我从一位值得信赖的同事那里得到了一个非常相似的错误。将 BundleID 更改为我的之后。我会遇到“agentBundle =”问题。

    我清理了 - 重建了。关闭并重新打开项目。最后在关闭并重新启动 XCode 之后 - 它按预期工作。

    不知道问题或解决方案在哪里......

    【讨论】:

    • 感谢您的评论。我真的不知道问题是什么。但我认为这可能与我为使 React Native 工作所做的更改有关。因为当我得到一个新的 M1 Mac mini 代码时,它在我的旧计算机上无法运行,而在新计算机上运行......
    猜你喜欢
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 2021-07-06
    相关资源
    最近更新 更多