UIActivityViewController中各个活动活动的不同活动项目

时间:2013-11-24 15:56:42

标签: ios iphone objective-c uiactivityviewcontroller

是否可以为UIActivityViewController中的每项活动活动使用不同的活动项目?例如,我有以下代码:

NSArray *objectsToShare = @[schemeURL, wordedString];
controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];

// Exclude all activities except AirDrop.
NSArray *excludedActivities = @[UIActivityTypePostToTwitter,
                                    UIActivityTypePostToWeibo,
                                    UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
                                    UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
                                    UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;
[self presentViewController:controller animated:YES completion:nil];

我想将数据设置为发送到Facebook wordedString属性,并将数据设置为通过AirDrop发送到属性schemeURL。这可能吗?提前谢谢。

1 个答案:

答案 0 :(得分:2)

您可以将UIActivityItemProvider子类化,并且可以使用以下方法检查活动类型。试试看

//- Returns the data object to be acted upon. (required)
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType
{
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
    NSString *theText = @"Some text for Facebook";
    return theText;
}

if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
    NSString *theText = @"Some text for Twitter";
    return theText;
}

if ([activityType isEqualToString:UIActivityTypePostToWeibo]) {
    NSString *theText = @"Some text for Weibo";
    return theText;
}

if ([activityType isEqualToString:UIActivityTypeMail]) {
    NSString *theText = _someText;
    return theText;
}

if ([activityType isEqualToString:kYourCustomMailType]) {
    NSString *theText = @"Some text for your Custom Type";
    return theText;
    }

return @"Some default text";

}