简体   繁体   English

如何在iOS 8系统范围的共享菜单中列出?

[英]How to get listed in the iOS 8 system wide share menu?

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). 我正在尝试在iOS 8系统范围的共享菜单中列出我的iOS 8应用程序,用于图像扩展名.png,.jpg(.jpeg),. gif(静态)。 What do I need to add to the info.plist file? 我需要添加到info.plist文件中? 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. 我从iOS文档示例中尝试了下面的代码但是没有用,我的应用程序没有显示在共享列表中。

<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 为了说清楚,这是iOS 8 Share Menu (也称为share sheet )我的意思是: http//cdn1.tekrevue.com/wp-content/uploads/2014/09/ios8-share-sheets-customize。 JPG

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 请参阅: 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 创建如下所示的类:在YourActivity.h文件中

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

and in the YourActivity.m file 并在YourActivity.m文件中

#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];
}

You are missing the NSExtensionActivationRule. 您缺少NSExtensionActivationRule。 See Apple's Extension programming guide: Declaring Supported Data Types for a Share or Action Extension 请参阅Apple的扩展编程指南: 声明共享或操作扩展的支持数据类型

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: 例如,要声明您的Share扩展可以支持最多十个图像,一个电影和一个网页URL,您可以使用以下字典作为NSExtensionAttributes键的值:

 <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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM