如何通过uiactivityviewcontroller分享不同的网址?

时间:2015-06-08 18:45:14

标签: ios xcode share analytics uiactivityviewcontroller

我正在尝试使用UIActivityViewController为每个项共享不同的URL。例如对于twitter:www.google.com;对于Facebook:www.bing.com

我知道我可以为每个人自定义文本,但我似乎无法找到为每个人自定义网址的方法。

我已经尝试了UIActivityItemProvider的子类,但它没有用完:

文件.m

- (id)initWithText:(NSString *)text{

if ((self = [super initWithPlaceholderItem:text])) {
    self.text = text ?: @"";
    self.url = @"";
}
    return self;
}

- (id)item {
    NSString *activityType = self.activityType;

    if ([self.placeholderItem isKindOfClass:[NSString class]]) {

        if ([self.activityType isEqualToString:UIActivityTypePostToFacebook]) {

            self.url = kSHARELINK_FB;

        } else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {

            self.url = kSHARELINK_TWITTER;


        } else if ([activityType isEqualToString:UIActivityTypeMessage]) {

            self.url = kSHARELINK_SMS;


            } else if([activityType 

isEqualToString:UIActivityTypeMail]){
            self.url = kSHARELINK_EMAIL;


        }else if ([activityType 

isEqualToString:UIActivityTypePostToWeibo]){
            self.url = kSHARELINK_WEIBO;

        }else{

            self.url = kSHARELINK_OTHER;

        }
    }

    return self.placeholderItem;
}

FILE .h

 @interface LLCustomActivityItemProvider : UIActivityItemProvider

@property (copy, nonatomic) NSString *text;
@property (copy, nonatomic) NSString *url;

- (id)initWithText:(NSString *)text;

1 个答案:

答案 0 :(得分:3)

事实证明我错过了return self.url; ...

- (id)item {
    NSString *activityType = self.activityType;

    if ([self.placeholderItem isKindOfClass:[NSString class]]) {

        if ([self.activityType isEqualToString:UIActivityTypePostToFacebook]) {

            self.url = kSHARELINK_FB;

        } else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {

            self.url = kSHARELINK_TWITTER;


        } else if ([activityType isEqualToString:UIActivityTypeMessage]) {

            self.url = kSHARELINK_SMS;


            } else if([activityType isEqualToString:UIActivityTypeMail]){
            self.url = kSHARELINK_EMAIL;


        }else if ([activityType isEqualToString:UIActivityTypePostToWeibo]){
            self.url = kSHARELINK_WEIBO;

        }else{

            self.url = kSHARELINK_OTHER;

        }
      return self.url;
    }

    return self.placeholderItem;
}