问题
I am trying to implement the Share functionality using UIActivityViewController. Using Swift 5, Xcode 11.2.1, ios 13.2.
I have used UITableViewController and in the rows's click I have called the share() method as shown below :
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)
}
}
I get the below error on clicking of the 'Share with friends' row. The strange thing is that the error doesn't occur always.
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
I see that the error was there in iOS 9 here and here. I cannot comment on these issues itself asking if they have been solved because I don't have the required reputation. As mentioned in these issues -
- I have used a UITableViewController in the Storyboard, so I have not manually added any constraints.
- I tried using the sourceRect mentioned here, but to no avail.
Also, I got the error when I ran the app on an actual device. The simulator does not give the error.
Could someone help me fix this error? Or is this issue known and is not fixed? Thanks.!
回答1:
This is Apple’s bug, not yours. Ignore the console message and move on.
回答2:
I don't know if this will work with you, but one of the other engineers on our team found that the wrapping the present(_:animated:)
call in a dispatch block seems to resolve the issue (at least in our app).
DispatchQueue.main.async {
self.present(controller, animated: true)
}
来源:https://stackoverflow.com/questions/58911158/why-is-uiactivityviewcontroller-displaying-auto-constraint-errors-in-console