当前位置: 动力学知识库 > 问答 > 编程问答 >

iphone - Hyper link in iOS Facebook

问题描述:

I need to share the link to Facebook. when user press that link that should take user to another page.

I tried the following code..but it only just share string..it doest not act like hyperlink..

-(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);

}

}];

}

网友答案:

Read this : https://developers.facebook.com/docs/ios/share/

You need to use " link" key for sharing links to facebook.

Ex :

[NSMutableDictionary dictionaryWithObjectsAndKeys:text,@"link", // < ----
                     dataImage,@"picture",
                     @"image/png",@"content_type"
                     ,nil];
分享给朋友:
您可能感兴趣的文章:
随机阅读: