Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to share different urls via uiactivityviewcontroller?

I am trying to use UIActivityViewController share different URLs for each item. e.g. For twitter : www.google.com ; For Facebook : www.bing.com

I know that I can customize the text for each one but I can't seem to find a way to customize the url for each one.

I've tried subclassing UIActivityItemProvider but it didn't work out:

FILE .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;
like image 889
jonypz Avatar asked Jun 08 '15 18:06

jonypz


1 Answers

It turns out that I was missing a 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;
}
like image 155
jonypz Avatar answered Oct 07 '22 04:10

jonypz