Kav*_*sha 8 uiactivityviewcontroller swift ios13
我正在尝试使用 UIActivityViewController 实现共享功能。使用 Swift 5、Xcode 11.2.1、ios 13.2。
我使用了 UITableViewController 并在行的单击中调用了 share() 方法,如下所示:
class SettingsTableViewController: UITableViewController {
var tableData = ["Share with friends"]
// MARK: - Table view methods
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return tableData.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "settingsCell", for: indexPath)
let row = indexPath.row
cell.textLabel?.text = tableData[row]
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
share()
}
func share() {
print("Share with friends")
let items: [Any] = ["This app is my favorite", URL(string: "https://www.apple.com")!]
let ac = UIActivityViewController(activityItems: items, applicationActivities: nil)
self.present(ac, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
单击“与朋友分享”行时出现以下错误。奇怪的是,该错误并不总是发生。
2019-11-18 14:28:23.951523+0530 ShareSheetDemo[425:18210] [LayoutConstraints] Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want.
Try this:
(1) look at each constraint and try to figure out which you don't expect;
(2) find the code that added the unwanted constraint or constraints and fix it.
(
"<NSLayoutConstraint:0x282b740f0 _UIActivityActionCellTitleLabel:0x11fd94510.height >= 22 (active)>",
"<NSLayoutConstraint:0x282b692c0 V:|-(15)-[_UIActivityActionCellTitleLabel:0x11fd94510] (active, names: '|':UIView:0x11fd92fb0 )>",
"<NSLayoutConstraint:0x282b69540 V:[_UIActivityActionCellTitleLabel:0x11fd94510]-(15)-| (active, names: '|':UIView:0x11fd92fb0 )>",
"<NSLayoutConstraint:0x282b74280 'UIView-Encapsulated-Layout-Height' UIView:0x11fd92fb0.height == 50.5 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x282b740f0 _UIActivityActionCellTitleLabel:0x11fd94510.height >= 22 (active)>
Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2019-11-18 14:28:25.925309+0530 ShareSheetDemo[425:18241] [ShareSheet] connection invalidated
Run Code Online (Sandbox Code Playgroud)
我发现 iOS 9 中存在错误(此处和此处)。我无法对这些问题本身发表评论,询问它们是否已经解决,因为我没有所需的声誉。正如这些问题中提到的 -
另外,当我在实际设备上运行该应用程序时,我收到了错误。模拟器不会报错。
有人可以帮我修复这个错误吗?或者这个问题是已知的并且尚未解决?谢谢。!
我不知道这是否适合您,但我们团队中的一位其他工程师发现将调用包装present(_:animated:)在调度块中似乎可以解决问题(至少在我们的应用程序中)。
DispatchQueue.main.async {
self.present(controller, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1897 次 |
| 最近记录: |