简体   繁体   English

UIActivityController行为在设备和模拟器上有所不同

[英]UIActivityController behaviour different on device and simulator

I add an activityViewController to my app like below, passing in an image 我将ActivityViewController如下所示添加到我的应用中,并传入图像

UIActivityViewController *avc = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:img,nil] applicationActivities:[NSArray arrayWithObjects:nil]];
        [self presentModalViewController:avc animated:YES];
        [avc release];

On the simulator (twitter, facebook and weibo accounts all not configured): 在模拟器上(推特,Facebook和微博帐户均未配置):

options mail, twitter, facebook, weibo, assign to contact, save to camera roll, print, and copy appear by default. 默认情况下,选项邮件,推特,脸书,微博,分配给联系人,保存到相机胶卷,打印和复制。

but on device: 但在设备上:

in my app: twitter, facebook and weibo only show if the accounts are configured. 在我的应用中:twitter,facebook和weibo仅显示是否配置了帐户。

in safari: twitter, facebook and weibo options are available irregardless of whether the accounts are configured. 在safari中:无论是否配置了帐户,都可以使用twitter,facebook和weibo选项。

I am expecting the same behaviour in my app as safari. 我期望我的应用程序中的行为与野生动物园相同。 am I missing a particular step? 我是否缺少特定步骤?

Okay I have figured the problem. 好吧,我知道了问题所在。

The options shown in the UIActivityViewController totally depends on the type of items that are to be shared. UIActivityViewController中显示的选项完全取决于要共享的项目的类型。 For example, if there is a video, it will not show Facebook or twitter option. 例如,如果有视频,则不会显示Facebook或Twitter选项。 But if it's an image and title, it definitely will show the relevant options. 但是,如果它是图像和标题,则肯定会显示相关选项。

The following will show up apps like mail, twitter, Facebook, assignToContact, save to camera roll, print, copy, etc 以下将显示诸如邮件,Twitter,Facebook,assignToContact,保存到相机胶卷,打印,复印等应用程序

// Create the content
NSString *message = @"The Upcoming App Scribble Talk";
UIImage *imageToShare = [UIImage imageNamed:@"createbtn.png"];

NSArray *objectsToShare = [NSArray arrayWithObjects:message, image, nil];

However, the following shall bring up only camera roll, mail or copy. 但是,以下内容只能调出相机胶卷,邮件或副本。

NSString *message = @"The Upcoming App Scribble Talk";
NSString *videoToShare = @"myFirsScribble.mov";
NSURL *videoPath = [NSURL fileURLWithPath:videoToShare];

NSArray *objectsToShare = [NSArray arrayWithObjects:message, videoPath, nil];

I think you want to show some certain service only in your UIActivityViewController. 我认为您只想在UIActivityViewController中显示某些特定服务。 You may one property called excludedActivityTypes to be defined as below to avoid some default activity. 您可以如下定义一个称为excludedActivityTypes属性,以避免某些默认活动。

UIActivityViewController *yourvc = [[UIActivityViewController alloc]initWithActivityItems:[NSArray arrayWithObjects:img,nil] applicationActivities:[NSArray arrayWithObjects:nil]];
yourvc.excludedActivityTypes = @[UIActivityTypePostToWeibo,UIActivityTypePrint,UIActivityTypeMail,UIActivityTypeCopyToPasteboard];//Try this code in simulator.. you can only see FB & Twitter.  
        [self presentModalViewController:yourvc animated:YES];
        [avc release];

likewise you can excluded from default UIActivityViewController.. 同样,您可以从默认的UIActivityViewController中排除。

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

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