Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController taking long time to present

Tags:

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?

like image 837
Maximilian Litteral Avatar asked Dec 17 '12 01:12

Maximilian Litteral


2 Answers

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.

like image 183
Matej Balantič Avatar answered Oct 22 '22 09:10

Matej Balantič


I was having the same issue on iOS 7. When I removed UIActivityTypeAirDrop from the allowed activity types, however, the controller appears almost instantly.

like image 44
bmueller Avatar answered Oct 22 '22 11:10

bmueller