Ios 我们如何在UIViewController类中使用uiactivity类方法-(void)性能?
我正在为iPhone构建一个阅读文章的应用程序。我陷入了一些问题。我在社交分享方面遇到了一个问题。我试过几种方法。 第一种方法 我们正在使用Facebook sdk共享文章链接、标题和图片。理想情况下,当我们在uiactivityviewcontroller中单击Facebook活动项时,我的Facebook sdk代码应该运行,但我无法运行 第二种方法 我们在uiactivityviewcontroller中尝试了自定义活动项,并成功地创建了自定义图标,并对uiactivity类的默认方法进行了操作-void performativity,但我想在我的视图控制器类中使用此方法,在该类中,我们通过segue传递文章链接、标题和图像 这是我的密码:Ios 我们如何在UIViewController类中使用uiactivity类方法-(void)性能?,ios,objective-c,share,uiactivityviewcontroller,uiactivity,Ios,Objective C,Share,Uiactivityviewcontroller,Uiactivity,我正在为iPhone构建一个阅读文章的应用程序。我陷入了一些问题。我在社交分享方面遇到了一个问题。我试过几种方法。 第一种方法 我们正在使用Facebook sdk共享文章链接、标题和图片。理想情况下,当我们在uiactivityviewcontroller中单击Facebook活动项时,我的Facebook sdk代码应该运行,但我无法运行 第二种方法 我们在uiactivityviewcontroller中尝试了自定义活动项,并成功地创建了自定义图标,并对uiactivity类的默认方法进行
#import "ysAPActivityIcon.h"
#import <Social/Social.h>
#import <FacebookSDK/FacebookSDK.h>
@implementation ysAPActivityIcon
- (NSString *)activityType { return @"it.albertopasca.myApp"; }
- (NSString *)activityTitle { return @"Open Maps"; }
- (UIImage *) _activityImage { return [UIImage imageNamed:@"iPad_jobs.png"]; }
- (BOOL) canPerformWithActivityItems:(NSArray *)activityItems { return YES; }
- (void) prepareWithActivityItems:(NSArray *)activityItems { }
- (UIViewController *) activityViewController { return nil; }
- (void) performActivity {
}
// my view controller class:
#import "ysAPActivityProvider.h"
#import "ysAPActivityIcon.h"
#import "ysDetailViewController.h"
@interface ysDetailViewController() <UIWebViewDelegate,UIActivityItemSource>
- (void) performActivity {
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:@"https://www.youtube.com/watch?v=pa8lsBNG31c"];
// // If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
// Present share dialog
[FBDialogs presentShareDialogWithLink:params.link
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error publishing story: %@", error.description);
} else {
// Success
NSLog(@"result %@", results);
}
}];
// If the Facebook app is NOT installed and we can't present the share dialog
} else {
// FALLBACK: publish just a link using the Feed dialog
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"YourStory", @"name",
nil];
// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error publishing story: %@", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User canceled.
NSLog(@"User cancelled.");
} else {
// Handle the publish feed callback
// NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
// if (![urlParams valueForKey:@"post_id"]) {
// User canceled.
NSLog(@"User cancelled.");
// } else {
// User clicked the Share button
// NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
// NSLog(@"result %@", result);
}
}
}];
}
}
在自定义UIActivity的.h文件中,创建标题、链接、图像所需的变量。。。在ViewController的实现文件中导入UIActivity的头文件,并在按钮的操作方法中创建类的实例。假设UIActivity头文件称为customAct:
customAct *act = [[customAct alloc] init];
然后使用它向头文件中的变量添加数据:
act.titleString = @"Text you want to add"
然后在性能方法中使用这些变量
但如果我理解的很好,你是在尝试分享给Facebook。UIActivityController默认为您提供在facebook、twitter、邮件和消息上共享的功能。永远不要让facebook共享按钮出现,你必须在设置中登录到你的facebook帐户,twitter也是如此。
另一方面,UIActivtyController不提供通过whatsapp、instagram等进行共享的功能。。。为此,您必须进行定制活动