7
我想使用UIActivityViewController爲每個項目共享不同的URL。例如對於twitter:www.google.com;對於Facebook:www.bing.com如何通過uiactivityviewcontroller分享不同的網址?
我知道我可以自定義每個文本,但我似乎無法找到一種方法來定製每個網址。
我試着子類UIActivityItemProvider,但它沒有工作:
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
@interface LLCustomActivityItemProvider : UIActivityItemProvider
@property (copy, nonatomic) NSString *text;
@property (copy, nonatomic) NSString *url;
- (id)initWithText:(NSString *)text;