0
  • My application is only for iPhone and when I run same application on iPad in 1x & 2x mode then UIActivityViewController does not showing facebook & twitter icon also mail icon is not proper. Although the functionality is working properly.
  • As per configuration respective accounts are already configured in Settings.
  • This issue only occurs on iPad but works fine on iPhone.

    - (void)onShare:(id)sender {
    
    UIActivityViewController *activityView = [[UIActivityViewController alloc] initWithActivityItems:@[@"World Cup! 2015",[UIImage imageNamed:@"WC15"]] applicationActivities:nil] ;
    
    [activityView setExcludedActivityTypes:[NSArray arrayWithObjects:
                                        UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo, UIActivityTypeAirDrop, UIActivityTypePrint,nil]];
    
    [self presentViewController:activityView animated:YES completion:nil];
    

    }

Only Facebook & Twitter icon missing.

Here is a screenshot

enter image description here

iOSarang
  • 11
  • 6

2 Answers2

0

The reason is we need to use UIPopOverViewController for iPad and UIActivityViewController for iPhone.

Please look out this question for detailed description : UIActivityViewController crashing on iOS8 iPads

Here's the code you need to use to resolve this issue:

UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObject:@"Test",nil] applicationActivities:nil];

//if iPhone
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
    [self presentViewController:controller animated:YES completion:nil];
}
//if iPad
else {
    // Change Rect to position Popover
    UIPopoverController *popup = [[UIPopoverController alloc] initWithContentViewController:controller];
    [popup presentPopoverFromRect:CGRectMake(self.view.frame.size.width/2, self.view.frame.size.height/4, 0, 0)inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

NOTE :- UIPopoverController is not available on an iPhone. From the documentation: "Popover controllers are for use exclusively on iPad devices. Attempting to create one on other devices results in an exception (If your app is iPhone only then this exception comes)."

Reference Link :- 'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.'

Might this helps you.

Thanks

Community
  • 1
  • 1
Harjot Singh
  • 6,767
  • 2
  • 38
  • 34
  • Thanks for reply. But, I have only iPhone app and if you see iPhone app's UI render on iPad so, **if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)** also fails this condition in iPad(Try if you want).This is not correct answer. I had changed to customized UIView with animation like UIActivityController cause sharing activity items are constant. – iOSarang Jun 16 '15 at 12:55
0

As solution for above issue, I just created customized UIView with required animation and for items each different implementation. The only solution I explored.

Robert
  • 5,278
  • 43
  • 65
  • 115
iOSarang
  • 11
  • 6