Mani murugan
Mani murugan

Reputation: 1802

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);
         }
     }];
}

Upvotes: 0

Views: 74

Answers (1)

Maulik
Maulik

Reputation: 19418

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];

Upvotes: 1

Related Questions