How can I add a ActivityItem to upper activity bar in UIActivityViewController?
Asked Answered
U

3

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

Unofficial answered 19/10, 2013 at 17:35 Comment(0)
L
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;

Lakitalaks answered 19/10, 2013 at 18:1 Comment(6)
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?Quetzalcoatl
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. https://mcmap.net/q/821891/-uiactivity-won-39-t-show-image/… - the same issue as yoursLakitalaks
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.Quetzalcoatl
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 senseLakitalaks
You can make them colorful with this post's strategy: https://mcmap.net/q/821892/-uiactivityviewcontroller-with-custom-uiactivity-displays-color-image-as-grayNingpo
@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 warningsLakitalaks
L
3

In Swift,

override static func activityCategory() -> UIActivityCategory
{
    return .Share
}
Landside answered 19/4, 2016 at 5:53 Comment(0)
B
0

Swift 3 version:

public override static var activityCategory: UIActivityCategory {
    return .share;
}
Burtie answered 20/6, 2018 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.