Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController, Unable to simultaneously satisfy constraints, on devices 8.x when compiled for iOS 7.x

I have an UIActivityViewController that is shown on an UIViewController (named viewCon here) :

// items contains text and/or image
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact];

[viewCon presentViewController:activityViewController animated:YES completion:NULL];

I'm using Xcode 6.1. My app has a Deployment Target to 7.0. I run it on two physical iPhones (5S (8.0.2) and 6 (8.1)).
When I compile my app for iOS 7.x on a physical device (not on simulators), the UIActivityViewController is shown and works but it appears on all the screen (the height is too big) and this log messages are printed in the Output :

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:0x1742941e0 UIView:0x174385960.bottom == _UIAlertControllerView:0x134ef4fc0.bottom>",
"<NSLayoutConstraint:0x174293d80 V:|-(0)-[UIView:0x170385960]   (Names: '|':_UIAlertControllerView:0x134ef4fc0 )>",
"<NSLayoutConstraint:0x17429a270 UIView:0x170385960.bottom <= _UIAlertControllerView:0x134ef4fc0.bottom>",
"<NSLayoutConstraint:0x174292cf0 UIView:0x174385960.centerY == UIView:0x170385960.centerY>",
"<NSLayoutConstraint:0x174294410 V:|-(>=8)-[UIView:0x174385960]   (Names: '|':_UIAlertControllerView:0x134ef4fc0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x17429a270 UIView:0x170385960.bottom <= _UIAlertControllerView:0x134ef4fc0.bottom>

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.

When I compile and run for iOS 8.x everything works well. But of course I need to compile for iOS 7.x for compatibility.
The UIViewController uses a .xib that use Autolayout. But I tried to not use Autolayout and the same issue appear. I tried in two other projects, also on iOS 7 and it's still the same.

I also tried to add this code before presenting the activityViewController, but same issue :

[activityViewController.view setTranslatesAutoresizingMaskIntoConstraints:NO];

I saw that others developers had the same issue (here) but it was caused by Xcode 6 beta. I've the version 6.1.

like image 581
Jonathan Avatar asked Dec 26 '22 03:12

Jonathan


1 Answers

I guess this is an iOS7 bug. It appears with some special sourceRect value. You can fix it by set another sourceRect, for example you can try:

[activityView popoverPresentationController].sourceRect=CGRectMake( 0,200,768,20);
like image 128
archdemo Avatar answered Dec 28 '22 10:12

archdemo