I made an app for iPhone. Now, I'm recreating it for iPad.
When the user selects the action button in the toolbar, a popover should show with a UIActivityViewController
, but for some reason, it's taking about 10 seconds for it to show the first time. On iPhone, it takes about a second. It's the same code except for the popover.
I tried disabling the popover, but it still takes around 10 seconds to show.
Here is the code:
-(IBAction)Actions:(UIBarButtonItem*)sender { if ([activityPopover isPopoverVisible] == YES) { [activityPopover dismissPopoverAnimated:YES]; return; } UIWebView *currentWebView = ((TabView *)self.tabs[self.currentTabIndex]).webViewObject; NSString *currentURL = (NSString*)[currentWebView request].mainDocumentURL; if (currentURL == NULL) return; BookmarkActivity *bookmarkActivity = [[BookmarkActivity alloc] init]; UIActivityViewController *sharing = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObject:currentURL] applicationActivities:@[bookmarkActivity]]; activityPopover = [[UIPopoverController alloc] initWithContentViewController:sharing]; [activityPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES]; }
I have tested on my iPad 3 and my iPad mini, both take awhile to present this.
How can I solve the problem?
Good question, I just had the same problem. It is not really solvable. However, you may improve the user experience by creating an activity indicator and then sending the initialization of the UIActivityViewController to the background:
-(void)openIn:(id)sender { // start activity indicator [self.activityIndicator startAnimating]; // create new dispatch queue in background dispatch_queue_t queue = dispatch_queue_create("openActivityIndicatorQueue", NULL); // send initialization of UIActivityViewController in background dispatch_async(queue, ^{ NSArray *dataToShare = @[@"MyData"]; UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil]; // when UIActivityViewController is finally initialized, // hide indicator and present it on main thread dispatch_async(dispatch_get_main_queue(), ^{ [self.activityIndicator stopAnimating]; [self presentViewController:activityViewController animated:YES completion:nil]; }); }); }
It works like a charm. When the user touches the button, the activity indicator starts animating, thus indicating that the process will take a while.
I was having the same issue on iOS 7. When I removed UIActivityTypeAirDrop
from the allowed activity types, however, the controller appears almost instantly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With