how to share different urls via uiactivityviewcontroller?
I am trying to use UIActivityViewController share different URLs for each item. eg 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;
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;
}
链接地址: http://www.djcxy.com/p/26828.html