我正在努力实施本机共享对话框来自 Facebook 的示例应用程序。
这样做似乎有些问题。
到目前为止我所做的事情:
- 包含最新的 Facebook SDK
- 包括 AdSupport、社交、帐户、安全和 libsqlite3.dylib。
- 添加了来自 Facebook 的示例代码。
- 还将 -lsqlite3.0 -ObjC 添加到其他链接器标志
- 将应用程序 ID 添加到 plist
- 将 FBUserSettingsViewResources 包和 FacebookSDKResources.bundle 添加到项目中
但我似乎无法分享网址。共享对话框甚至没有出现。
我的代码如下所示:
视图控制器.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
{
IBOutlet UIButton *buttonShare;
}
- (IBAction)shareButtonClicked:(id)sender;
@end
视图控制器.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
无法共享 URL。需要一些这方面的指导。
- (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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)