0

I'm trying to get my iOS 8 app listed in the iOS 8 system wide share menu for the image extensions .png, .jpg (.jpeg), .gif (static). What do I need to add to the info.plist file? I tried the code below from the iOS docs example but that didn't work, my app isn't showing up in the share list.

<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>NSExtensionServiceRoleType</key>
<string>NSExtensionServiceRoleTypeEditor</string>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.ui-services</string>
<key>NSExtensionPrincipalClass</key>
<string>ActionViewController</string>
</dict>

To make it clear, this is the iOS 8 Share Menu (also known as share sheet) I mean: http://cdn1.tekrevue.com/wp-content/uploads/2014/09/ios8-share-sheets-customize.jpg

Tom
  • 5,588
  • 20
  • 77
  • 129
  • Define "didn't work". Keep in mind that the Photos and Mail apps (for some stupid, unknown reason) doesn't offer any chance to open images in 3rd party apps. – rmaddy Feb 13 '15 at 18:31
  • My app isn't showing up in the share menu list. I tried a couple of other apps as well and my app isn't in the list either. Is the string correct to get listed for image files?: `com.apple.ui-services` – Tom Feb 13 '15 at 18:35
  • You don't need an extension for this. You want to appear in the "Open in" menu. See http://stackoverflow.com/questions/2774343/how-do-i-associate-file-types-with-an-iphone-application/2781290#2781290 – rmaddy Feb 13 '15 at 18:40
  • No, the "Open In" menu is something different. I want my app to get listed in the Share Menu. – Tom Feb 13 '15 at 18:44

2 Answers2

0

First thing first, you need to understand about inter-app communication. What you need is custom url scheme for your app. Please Refer : https://developer.apple.com/library/ios/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/Inter-AppCommunication/Inter-AppCommunication.html

Now after you have a custom url sheme, proceed as follows:

To get listed in the system wide share menu,You need to make a custom Activity.

Make a class like the following: In the YourActivity.h file

@interface YourActivity : UIActivity
-(void)someInitialisationMethod:(NSString*)string;
@end

and in the YourActivity.m file

#import "YourActivity.h"

@implementation YourActivity

- (NSString *)activityType
{
return @"UIActivityCategoryShare";
}

- (NSString *)activityTitle
{ // here give the title of your app or the action name that it performs
return @"YourAppName";
}
+ (UIActivityCategory)activityCategory
{// there are two types of category- share and action
return UIActivityCategoryShare;
}
- (UIImage *)activityImage
{
// Note: These images need to have a transparent background and I recommend these sizes:
// iPadShare@2x should be 126 px, iPadShare should be 53 px, iPhoneShare@2x should be 100
// px, and iPhoneShare should be 50 px. I found these sizes to work for what I was making.

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    return [UIImage imageNamed:@"YourActivityImage.png"];
}
else
{
    return [UIImage imageNamed:@"YourActivityImage.png.png"];
}
}

- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
NSLog(@"%s", __FUNCTION__);
return YES;
}

- (void)prepareWithActivityItems:(NSArray *)activityItems
{
NSLog(@"%s",__FUNCTION__);
}

- (UIViewController *)activityViewController
{
NSLog(@"%s",__FUNCTION__);
return nil;
}

- (void)performActivity
{
// This is where you can do anything you want, and is the whole reason for          creating a custom
// UIActivity
NSURL *yourCustomURLMaybe = [NSURL URLWithString:someInitialisedString];
if ([[UIApplication sharedApplication] canOpenURL: yourCustomURL]) {
    [[UIApplication sharedApplication] openURL: yourCustomURL];
}
else
{
    NSLog(@"YourActivity not found");
}
[self activityDidFinish:YES];
}

@end

Now that your custom activity is made You need to fire it up with share menu like this

NSString *yourCustomUrl = [NSString stringWithFormat:@"YourCustomURLScheme?..."];

NSString *escapeAdded = [yourCustomUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSURL *finalCustomURL = [NSURL URLWithString:escapeAdded];

YourActivity *ca;
if ([[UIApplication sharedApplication] canOpenURL: finalCustomURL])
{
    ca = [[YourActivity alloc]init];
}
else
{
    ca = nil;
}

NSArray *applicationActivityArray = [[NSArray alloc] initWithObjects:ca,nil];

Finally, When you present the share box, add the above array to application Activities:

activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[...] applicationActivities:applicationActivityArray];
}
Abhishek Arora
  • 395
  • 2
  • 12
0

You are missing the NSExtensionActivationRule. See Apple's Extension programming guide: Declaring Supported Data Types for a Share or Action Extension

For example, to declare that your Share extension can support up to ten images, one movie, and one webpage URL, you might use the following dictionary for the value of the NSExtensionAttributes key:

<key>NSExtensionAttributes</key>
    <dict>
        <key>NSExtensionActivationRule</key>
        <dict>
            <key>NSExtensionActivationSupportsImageWithMaxCount</key>
            <integer>10</integer>
            <key>NSExtensionActivationSupportsMovieWithMaxCount</key>
            <integer>1</integer>
            <key>NSExtensionActivationSupportsWebURLWithMaxCount</key>
            <integer>1</integer>
        </dict>
    </dict>
Richard Venable
  • 8,310
  • 3
  • 49
  • 52
  • Will my app show up in the iOS 8 Share Menu if I add that to my info.plist or do I need to write an extension for it too? – Tom Feb 20 '15 at 21:50
  • @Tom, you need to add those attributes to the info.plist of your Share or Action extension. – Richard Venable Feb 20 '15 at 22:43
  • That's the confusing part for me. I would like to get my app invoked from the Share Menu and not an extension for the app. Will the code also work if I add it to my apps info.plist? – Tom Feb 20 '15 at 23:06
  • What you are referring to as the "Share Menu" is the menu opened by creating a UIActivityViewController. If you want to add something to a UIActivityViewController outside of your app, your only option is to create an extension. – Richard Venable Feb 21 '15 at 02:39