I just got this bug report for me app...the activity view controller is suddenly this weird narrow shape whether I'm on an actual phone or the view controller.
This is happening with some plain vanilla code that hasn't been touched in months:
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[message] applicationActivities:nil]; [self presentViewController:activityViewController animated:YES completion:nil];
What could be going wrong? I can't even think of where to start troubleshooting this one.
6 Answers
Answers 1
Maybe self.view.frame.size.width
is the problem. You can find your the frame with NSLog
self.view
. Simple workaround could be:
[self.view.window.rootViewController presentViewController:activityViewController animated:YES completion:nil];
Answers 2
In some cases it may happen. Try this
NSArray *Items = [NSArray arrayWithObjects: @"Checking Test App", nil]; UIActivityViewController *activity=[[UIActivityViewController alloc]initWithActivityItems:Items applicationActivities:nil]; [self presentViewController:activity animated:YES completion:nil];
or
NSString *string = NSLocalizedString(@"shareString", nil); UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[string] applicationActivities:nil]; [activityViewController setCompletionWithItemsHandler: ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *error) { if ( completed ) { NSLog(@"sharing complete"); } else { NSLog(@"cancelled"); } }]; [self presentViewController:activityViewController animated:YES completion:^{ }];
Answers 3
You should check frames for your self's view. Probably its width less than the width of the activityViewController and you get this bug.
Answers 4
These kinds of bugs do occur and they really test your patience and give you a challenge. Although I cannot give a definite answer, I can give you some tips on how to troubleshoot this!
What I suggest is that you first try to re-create this on your development machine. Then try to play around and see what's causing the issue. Here are some things to try out.
Run this on several devices with different OS's so that you might be able to determine a pattern.
Try and change the "
initWithActivityItems
" value(s) and see whether the problem occurs.See whether the issue exists if you try to create the ActivityViewController from a different view controller too.
Go through your code and see if there are any warnings that you have simply ignored. Specially if you're using Storyboards for creating the view.
I know this is not an answer, but I cannot post such a long response as a comment.
Hope this helps!
Answers 5
Have you tried reproducing this bug??? If we don't have the exact scenario of how this bug is getting created then we can't make a solution for it!!! Try updating the items in the array and check if the bug still exist... This type of things happens sometimes but until and unless we don't reproduce this scenario it can't be termed as bug.
Any way if you are working in universal app add below line of code before presenting the ActivityView
ActivityViewController.popoverPresentationController.sourceView = self.view; [self presentViewController:activityViewController animated:YES completion:nil];
I will suggest, instead of looking for a solution dig out the problem first. I have never seen such weird behaviour of ActivityView before this and if we know why this happened then it will be helpful to every iOS developer.
Answers 6
If you are on iPad, try setting the popoverPresentationController
property of sourceRect
NSString *string = NSLocalizedString(@"shareString", nil); UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[string] applicationActivities:nil]; activityVC.popoverPresentationController.sourceView = self.view; activityVC.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height-50, 1.0, 1.0); [self presentViewController:activityVC animated:YES completion:nil];
0 comments:
Post a Comment