我需要分享Facebook的链接。当用户按下应该将用户带到另一页的链接时。
我尝试了以下代码..但它只是共享字符串..这样做不像超链接..
-(void)fbShare
{
[hud show:YES];
NSString *title=[NSString stringWithFormat:@"www.google.com"];
MAAppDelegate *appdelegate = (MAAppDelegate *)[[UIApplication sharedApplication] delegate] ;
if (!appdelegate.session) {
appdelegate.session = [[FBSession alloc]initWithPermissions:[NSArray arrayWithObjects:@"publish_stream",nil]];
}
if (![appdelegate.session isOpen]) {
[appdelegate.session openWithCompletionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error) {
[self Share:title];
}else {
NSLog(@"facebook errror %@",error.description);
[hud hide:YES];
}
}];
} else {
[self Share:title];
}
}
-(void)Share:(NSString *)text
{
MAAppDelegate *appdelegate = (MAAppDelegate *)[[UIApplication sharedApplication] delegate];
UIImage *image = [UIImage imageNamed:@"bath3.png"];
[FBSession setActiveSession:appdelegate.session];
NSData *dataImage=UIImageJPEGRepresentation(image,1.0);
NSMutableDictionary *parameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:text, @"name", dataImage, @"picture", @"image/png", @"content_type", nil];
FBRequest *request=[FBRequest requestWithGraphPath:@"me/photos" parameters:parameters HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error) {
NSLog(@"Success");
[hud hide:YES];
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Audalize POC" message:@"Shared Successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
} else {
[hud hide:YES];
NSLog(@"failed %@",error.localizedDescription);
}
}];
}
答案 0 :(得分:1)
阅读本文:https://developers.facebook.com/docs/ios/share/
您需要使用“链接”键来分享指向facebook的链接。
前:
[NSMutableDictionary dictionaryWithObjectsAndKeys:text,@"link", // < ----
dataImage,@"picture",
@"image/png",@"content_type"
,nil];