ios – UIActivityViewController – 仅为某些活动附加URL

ios – UIActivityViewController – 仅为某些活动附加URL,第1张

概述我一直在尝试使用新的UIActivityViewController替换所有的UIActionSheets进行共享,但是我遇到了一个问题. 我有5个活动,Message,Email,Copy,Twitter和Facebook.我已经弄清楚如何让他们显示不同的文字,通过这个定制的UIActivityProvider子类: - (id) activityViewController:(UIActivi 我一直在尝试使用新的UIActivityVIEwController替换所有的UIActionSheets进行共享,但是我遇到了一个问题.

我有5个活动,Message,Email,copy,Twitter和Facebook.我已经弄清楚如何让他们显示不同的文字,通过这个定制的UIActivityProvIDer子类:

- (ID) activityVIEwController:(UIActivityVIEwController *)activityVIEwController      itemForActivityType:(Nsstring *)activityType{    if ( [activityType isEqualToString:UIActivityTypePostToTwitter] )        return twitter;    if ( [activityType isEqualToString:UIActivityTypePostToFacebook] )        return facebook;    if ( [activityType isEqualToString:UIActivityTypeMessage] )        return urlScheme;    if ( [activityType isEqualToString:UIActivityTypeMail] )        return urlScheme;    if ( [activityType isEqualToString:UIActivityTypecopytopasteboard])        return urlScheme;    return nil;}

这在我看来控制器:

ActivityProvIDer *aProvIDer = [[ActivityProvIDer alloc] init];    aProvIDer.facebook = facebook;    aProvIDer.twitter = twitter;    aProvIDer.urlScheme = URL;    NSArray *Items = @[aProvIDer,sharedURL];    UIActivityVIEwController *activityVC = [[UIActivityVIEwController alloc]initWithActivityItems:Items applicationActivitIEs:Nil];    activityVC.excludedActivityTypes = @[UIActivityTypePrint,UIActivityTypeAssignToContact,UIActivityTypeSavetoCameraRoll,UIActivityTypePostToWeibo];    [self presentVIEwController:activityVC animated:TRUE completion:nil];

但是,我只想在Facebook和Twitter分享表中显示URL(sharedURL),而不是邮件,电子邮件或副本.任何方式来完成这个?

解决方法 您可以选择要发送给每种类型的活动.我创建了一个自定义活动提供者,并将其称为:
NSMutableArray *activityItems = [NSMutableArray array];     CustomActivityItemProvIDer *activityItemProvIDer =     [[CustomActivityItemProvIDer alloc] initWithText:text                                                     urlText:urlString];     [activityItems addobject:activityItemProvIDer];     //you can have your own custom activitIEs too:     NSArray *applicationActivitIEs = @[[CustomActivity new],[OtherCustomActivity new]];     UIActivityVIEwController *vc = [[UIActivityVIEwController alloc]initWithActivityItems:activityItems                                                                     applicationActivitIEs:applicationActivitIEs];

自定义提供程序是UIActivityItemProvIDer的子类

@interface CustomActivityItemProvIDer : UIActivityItemProvIDer- (ID)initWithText:(Nsstring *)text urlText:(Nsstring *)url;@end

我的自定义提供程序类的内容看起来像这样:

- (ID)initWithText:(Nsstring *)text urlText:(Nsstring *)url{    if ((self = [super initWithPlaceholderItem:text])) {               self.text = text ?: @"";        self.url = url ?: @"";    }       return self;}- (ID)item {       Nsstring *activityType = self.activityType;    if ([self.placeholderItem isKindOfClass:[Nsstring class]]) {                    if ([self.activityType isEqualToString:UIActivityTypePostToFacebook] ||            [self.activityType isEqualToString:UIActivityTypeMail]) {            return [Nsstring stringWithFormat:@"%@\n%@",self.text,self.url];        } else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {            return [self findBestStringOfLength:kTwitterMessageLength hashTags:YES];        } else if ([activityType isEqualToString:UIActivityTypeMessage]) {            return [self findBestStringOfLength:kSMSMessageLength hashTags:YES];        } else {            return self.text;        }    }    return self.placeholderItem;}
总结

以上是内存溢出为你收集整理的ios – UIActivityViewController – 仅为某些活动附加URL全部内容,希望文章能够帮你解决ios – UIActivityViewController – 仅为某些活动附加URL所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1095181.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存