gpt4 book ai didi

ios - 如何通过 uiactivityviewcontroller 共享不同的 url?

转载 作者:可可西里 更新时间:2023-11-01 03:32:53 26 4
gpt4 key购买 nike

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

我知道我可以为每个人自定义文本,但我似乎无法找到一种方法来为每个人自定义 url。

我已经尝试子类化 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;
}

文件.h

 @interface LLCustomActivityItemProvider : UIActivityItemProvider

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

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

最佳答案

原来我少了一个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;
}

关于ios - 如何通过 uiactivityviewcontroller 共享不同的 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30716759/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com