15

I like to add my own WhatsApp ActivityItem to the UIActivityViewController, but it is always added to the lower non colored activity bar, but I like to add it to the upper bar, the one with the colored items.

Thats the code I use:

WhatsApp *whatsApp = [[WhatsApp alloc] init];
            UIActivityViewController* activityVC = [[UIActivityViewController alloc] initWithActivityItems:@[image, text] applicationActivities:@[whatsApp]];

Like.enter image description here

Petro Korienev
  • 4,007
  • 6
  • 34
  • 43
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98

3 Answers3

43

In your custom UIActivity subclass you have to simply override one method:

+ (UIActivityCategory)activityCategory
{
   return UIActivityCategoryShare;
}

There are to possible categories: action and share.
It's important, this is class method, not instance. Also, it's iOS 7 specific - all action activities are placed in bottom line (if any), then above the share activities and then above AirDrop. So, if you want to get rid of bottom line for example, simply exclude all action activities. If you want to put something in share/action line - override activityCategory. default is UIActivityCategoryShare;

Petro Korienev
  • 4,007
  • 6
  • 34
  • 43
  • 1
    Ok, the item is moved to the top now, but I have a gray square instead of the icon, the icons size is 60x60. and it is a PNG formate. Any idea why? – David Gölzhäuser Oct 20 '13 at 18:49
  • 1
    Your custom activities cannot be colourful. The iOS takes your icon and processes icon by itself - say your icon is just mask. Also, if i'm not mistaken ios7 needs 70x70 icons for activity items. http://stackoverflow.com/questions/18942893/uiactivity-wont-show-image/18943308#18943308 - the same issue as yours – Petro Korienev Oct 21 '13 at 03:50
  • Korienv So there cant be any color except gray in a costume UIActivity, even in UIActivityCategoryShare?! Thats not good, I don't like that:/ Thanks anyway tho! And for iPhone and iPod the image size on iOs 7 should be 60x60, I read it in the Apple docs. – David Gölzhäuser Oct 21 '13 at 07:19
  • There can't be any color except system-providen (yes, in fact gray). So differs iOS built-in share activities and application's custom activities. Looking deeper it makes sense – Petro Korienev Oct 21 '13 at 07:25
  • 2
    You can make them colorful with this post's strategy: http://stackoverflow.com/a/22670582/2578240 – Lugubrious Jul 10 '14 at 23:18
  • @Lugubirous, nice, but this is private API. However, I'm almost sure, this will pass the approval process without any problems - validation doesn't give any warnings – Petro Korienev Jul 11 '14 at 00:16
3

In Swift,

override static func activityCategory() -> UIActivityCategory
{
    return .Share
}
Hardik Darji
  • 3,633
  • 1
  • 30
  • 30
0

Swift 3 version:

public override static var activityCategory: UIActivityCategory {
    return .share;
}
Tim Autin
  • 6,043
  • 5
  • 46
  • 76