UIActivityItemSource Protocole设置复杂对象 [英] UIActivityItemSource Protocole set complex object

查看:110
本文介绍了UIActivityItemSource Protocole设置复杂对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 6的新方式来共享信息: UIActivityViewController 。要根据媒体(Facebook,Twitter或邮件)选择共享数据,我的视图控制器实现 UIActivityItemSource 协议,如下所示:

I'm using iOS 6 new way to share information : UIActivityViewController. To select the shared data depending on the media (facebook, twitter or mail) my view controller implement the UIActivityItemSource Protocol as follow :

- (IBAction)onShareButton:(UIButton *)sender
{

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[self] applicationActivities:nil];

    activityViewController.excludedActivityTypes = @[UIActivityTypeMessage, UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypeMessage, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll];
    [self presentViewController:activityViewController animated:YES completion:^{}];
}

#pragma mark - UIActivityItemSource Protocol

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
    if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
        NSArray *items = @[@"message facebook", [NSURL URLWithString:@"http://www.myUrlFacebook.com"]];
        return items;
    } else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
        NSArray *items = @[@"message twitter", [NSURL     URLWithString:@"http://www.myUrlTwitter.com"]];
        return items;
    } else if ([activityType isEqualToString:UIActivityTypeMail]) {
        NSArray *items = @[@"message mail", [NSURL URLWithString:@"http://www.myUrlMail.com"]];
        return items;
    }

        NSArray *items = @[@"Not a proper Activity", [NSURL URLWithString:@"http://www.myUrlMail.com"]];
    return items;
}

- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
    return @"PlaceHolder";
}

当我为返回一个简单的NSString时,activityViewController :itemForActivityType:我的 UIActivityViewController 很好地使用了该字符串,但我找不到使用数组的方法

When I'm returning a simple NSString for activityViewController:itemForActivityType: the string is well used by my UIActivityViewController, but I can't find a way to use an Array !

根据Apple文档,它应该是可能的:

According to Apple Documentation it should be possible :


此方法返回活动对象要执行的实际数据对象
Apple文档

有没有人使用过这个 UIActivityItemSource 带数组的协议,还是有一个使用完整的教程来做到这一点?

Does anyone ever use this UIActivityItemSource Protocol with Arrays, or is there a use full tutorial to do that ?

注意:我也遇到了这个错误控制台,它可能有帮助...

Note : I also got this error on the console, it may help ...


启动服务:注册未知的应用程序标识符com.apple.mobilemail失败ed

Launch Services: Registering unknown app identifier com.apple.mobilemail failed

启动服务:无法找到应用程序标识符com.apple.mobilemail

Launch Services: Unable to find app identifier com.apple.mobilemail


推荐答案

在花了大量时间试图弄清楚这个之后,似乎无法将它传递给 NSArray 项目。所以我扩展了 UIActivityViewController 以使其成为可能。

After spending a significant amount of time trying to figure this one out, it seems it isn't possible to pass it an NSArray of items. So I extended UIActivityViewController to make it possible.

RDActivityViewController

这篇关于UIActivityItemSource Protocole设置复杂对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆