本文介绍了iOS中的Facebook共享对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在试图在示例应用程序中从Facebook实施
I am trying to implement the native Share dialog from Facebook in a sample application.
似乎有一些问题这样做。
Seem to have some problem in doing so.
到目前为止我已经做的事情:
Things I have done so far:
- 包含最新的Facebook SDK
- 包括AdSupport,Social,Account,Security和libsqlite3.dylib。 / li>
- 从Facebook添加示例代码。
- 将-lsqlite3.0 -ObjC添加到其他链接器标志
- 将应用程序ID添加到plist
- 将FBUserSettingsViewResources包和FacebookSDKResources.bundle添加到项目中
- Included the latest Facebook SDK
- Included the AdSupport, Social, Account, Security and libsqlite3.dylib.
- Added the sample code from Facebook.
- Added -lsqlite3.0 -ObjC to Other Linker Flags as well
- Added the app id to the plist
- Added the FBUserSettingsViewResources bundle and FacebookSDKResources.bundle to the project
但我似乎不能共享URL。共享对话框甚至不会出现。
But I can't seem to share the URL. The share dialog doesn't even appear.
我的代码如下所示:
Viewcontroller.h
Viewcontroller.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIButton *buttonShare;
}
- (IBAction)shareButtonClicked:(id)sender;
@end
ViewController.m
ViewController.m
#import "ViewController.h"
#import <FacebookSDK/FacebookSDK.h>
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)shareButtonClicked:(id)sender
{
FBShareDialogParams *params = [[FBShareDialogParams alloc] init];
params.link = [NSURL URLWithString:@"https://developers.facebook.com/ios"];
params.picture = [NSURL URLWithString:@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
params.name = @"Facebook SDK for iOS";
params.caption = @"Build great apps";
[FBDialogs presentShareDialogWithParams:params clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if(error) {
NSLog(@"Error: %@", error.description);
} else {
NSLog(@"Success!");
}
}];
}
@end
无法共享网址。需要一些指导。
Not able to share the URL. Need some guidance on this.
推荐答案
- (IBAction)shareButtonClicked:(id)sender
{
// if the session is closed, then we open it here, and establish a handler for state changes
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
{
if (error)
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else if(session.isOpen)
{
NSString *str_img = [NSString stringWithFormat:@"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"];
NSDictionary *params = @{
@"name" :[NSString stringWithFormat:@"Facebook SDK for iOS"],
@"caption" : @"Build great Apps",
@"description" :@"Welcome to iOS world",
@"picture" : str_img,
@"link" : @"",
};
// Invoke the dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:
^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
//NSLog(@"Error publishing story.");
[self.indicator stopAnimating];
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
//NSLog(@"User canceled story publishing.");
[self.indicator stopAnimating];
} else {
//NSLog(@"Story published.");
[self.indicator stopAnimating];
}
}}];
}
}];
return;
}
这篇关于iOS中的Facebook共享对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!