为啥 ActivityViewController 在控制台中显示自动约束错误?

Posted

技术标签:

【中文标题】为啥 ActivityViewController 在控制台中显示自动约束错误?【英文标题】:Why is ActivityViewController displaying auto constraint errors in console?为什么 ActivityViewController 在控制台中显示自动约束错误? 【发布时间】:2015-06-20 12:45:32 【问题描述】:

我正在尝试在我的应用程序中实现一个分享按钮,所以很自然地,我求助于UIActivityViewController。出于某种原因,每当我按下分享按钮并弹出时,我的日志中都会收到以下消息:

    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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x7c0a65d0 V:[UIView:0x7c0a2fa0(<=528)]>",
    "<NSLayoutConstraint:0x7c0a6540 UIView:0x7c0a2fa0.height == UIView:0x7c0a2e60.height>",
    "<NSLayoutConstraint:0x7c0a7100 _UIAlertControllerView:0x7c0a27f0.height == UIView:0x7c0a2e60.height>",
    "<NSLayoutConstraint:0x7c0b1660 V:[_UIAlertControllerView:0x7c0a27f0(568)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7c0a65d0 V:[UIView:0x7c0a2fa0(<=528)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-06-20 15:32:43.885 App[19268:300248] 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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSLayoutConstraint:0x78fc3e70 V:[UIView:0x78ff1eb0(<=528)]>",
    "<NSLayoutConstraint:0x78fc3de0 UIView:0x78ff1eb0.height == UIView:0x78fb9670.height>",
    "<NSLayoutConstraint:0x78fc5aa0 _UIAlertControllerView:0x78ff69f0.height == UIView:0x78fb9670.height>",
    "<NSLayoutConstraint:0x78f58860 V:[_UIAlertControllerView:0x78ff69f0(568)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x78fc3e70 V:[UIView:0x78ff1eb0(<=528)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2015-06-20 15:32:48.691 App[19268:300248] viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" UserInfo=0x79982700 Message=Service Connection Interrupted

调用它时我没有做任何花哨的事情,只是最低限度的:

let someText:String = "Hello"
        let activityViewController = UIActivityViewController(activityItems: [someText], applicationActivities: nil)
        activityViewController.excludedActivityTypes =  [
            UIActivityTypePostToWeibo,
            UIActivityTypePrint,
            UIActivityTypeCopyToPasteboard,
            UIActivityTypeAssignToContact,
            UIActivityTypeSaveToCameraRoll,
            UIActivityTypeAddToReadingList,
            UIActivityTypePostToFlickr,
            UIActivityTypePostToVimeo,
            UIActivityTypePostToTencentWeibo
        ]          self.navigationController!.presentViewController(activityViewController,
            animated: true,
            completion: nil)

这可能是 Xcode beta 7/ios 9 的错误吗?还是我错过了什么?我应该担心吗?

【问题讨论】:

我在 Xcode beta 7/iOS 9 上遇到了同样的错误 【参考方案1】:

要么:

    这是一个 Apple 错误 - 只要它仍处于测试阶段,请向 https://feedbackassistant.apple.com/ 报告 您从超大视图控制器(帧中的错误?)呈现模式,然后约束 V:[UIView:0x7c0a2fa0(&lt;=528) 中断

你应该担心吗?

    它不会导致崩溃,但它仍然是一个程序员错误的迹象,日志在那里,理想情况下,如果你有意破坏它们,你应该为约束提供优先级

【讨论】:

我不认为我设置了那个限制,我只是经历了所有这些 尝试从代码中删除AllConstraints,或者如果您以编程方式调整它的大小 - 不要使用框架,为约束创建一个出口

以上是关于为啥 ActivityViewController 在控制台中显示自动约束错误?的主要内容,如果未能解决你的问题,请参考以下文章

在 UIActivity:activityViewController 期间显示 UIAlertView

为 ActivityViewController 提供的未知活动项

在 activityViewController 中更改 barTintColor

UIActivity activityViewController 没有在 iPad 上关闭

UIActivity 自定义 activityViewController 在 iPad 上崩溃

ActivityViewController 无法在 WhatsApp 和 Mail App 上共享链接?