复制/粘贴在带有 M1 Macbook Pro 模拟器的 Xcode 13 上不起作用。它可以在普通的 Mac PC 上运行。
等待 Apple 的修复,我设法创建一个自定义 MacOS 快捷方式来处理模拟器上的复制/粘贴。
以下是使其发挥作用的步骤:
通常应该可以工作。我同意击键有点慢,但没有找到任何其他方法使其正常工作。
点击 Siri 操作。可能会失败
以下是启用它的步骤:
不幸的是,对于很多使用 Xcode 12、13 的人来说,这是一个反复出现的问题 - 频率较低,但从 Xcode 14 开始似乎仍然存在。
有三种可能的解决方法:
Share
/ Simulator
。这将在您选择的模拟器中打开 URL。Files
应用程序打开文本文件来复制并粘贴任何数据。这是 M1 MacBook 的问题,Pasteboard 在最新的芯片和最新的模拟器中也存在此问题。
截至目前,苹果还没有这方面的更新。所以我们可以尝试其他的东西
• Save what you want to paste into a textedit file
• Drag and drop the .txt file into the simulator window
• The simulator will prompt you to Save the file in the Files App
• From the Simulator Open the file and copy the text you want
• Paste into your App
示例:- 确保在您的捆绑包中添加
yourfile.txt
。这里的文本字段数据将来自您的捆绑包文件。如果您不想在捆绑包中添加文件,甚至您也可以使用文档目录中的文件。
func testExample() throws {
let testBundle = Bundle(for: type(of: self))
guard let filePath = testBundle.path(forResource: "yourfile", ofType: "txt") else {
return
}
let fileURL = URL(fileURLWithPath: filePath)
let result = try String(contentsOf: fileURL, encoding: .utf8)
let app = XCUIApplication()
app.launch()
let textField = app.textFields["textFieldId"]
textField.tap()
textField.typeText(result)
let resultLabel = app.staticTexts["resultId"]
app.buttons["buttonId"].tap()
XCTAssertEqual(textField.value as! String, resultLabel.label)
}
如果是链接,您可以直接将其从桌面Chrome / Safari地址栏拖到正在运行的模拟器窗口中,它将弹出移动Safari并打开该链接。
Apple 已禁用证书拖放和文本复制粘贴,但我们的开发人员不能因为这种破坏可用性的可怜尝试而推迟! /s
自从我在 2020 年获得 M1 以来,我只能在 Xcode 11.x 或更低版本中使用复制/粘贴。 我没有找到任何可以在 Xcode 13 上再次启用复制/粘贴的模拟器或其他复选框的设置