0

I am using the following string to format a URL in a facebook post from my app.

NSString *stringAppURLFormatted = [NSString stringWithFormat:@"<a href= 'https://www.facebook.com'> New Game Name </a>"];

The output was

<a href= 'https://www.facebook.com'> New Game Name </a>

Though I was expecting the output to be

New Game Name

How can this be corrected?

UPDATED

Basically, I am using the code below, adding the NSString to an NSMutableDictionary. I am not too sure how to apply UIActivityViewController approach that has been widely recommended to this method.

-(void)postPictureWithText:(UIImage*)picture withTitle:(NSString*) title andDescription (NSString*)description
{
    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    //NSDictionary* paramsImmutable = params.copy;

    NSString *stringAppURLFormatted = [NSString stringWithFormat:@"<a href= 'https://www.facebook.com'> New Game Name </a>"];
    [params setObject:stringAppURLFormatted forKey:@"message"];

    [params setObject:UIImagePNGRepresentation(picture) forKey:@"picture"];
    [FBRequestConnection startWithGraphPath:@"me/photos"
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)
     {
         if (error)
         {
             //failure
             NSLog(@"ERROR in posting to facebook");
         }
         else
         {
             //success
             NSLog(@"Result after posting image successfully = %@",result);
         }
         // button.enabled = YES;
     }];
   }
  • http://stackoverflow.com/questions/23779400/how-to-make-hyperlink-on-a-string-and-share-in-facebook-ios – Noor Oct 13 '14 at 13:21
  • possible duplicate of [How do I customize a UIActivityViewController to show a URL link when posting to facebook and twitter?](http://stackoverflow.com/questions/12657817/how-do-i-customize-a-uiactivityviewcontroller-to-show-a-url-link-when-posting-to) – picciano Oct 13 '14 at 13:42
  • I just updated the question – errorallergic Oct 13 '14 at 15:20

1 Answers1

0

Can you provide more details on how you are posting that content to facebook ? If you're using an UIActivityViewController instance, there's a good article about it at NSHipster: UIActivity​View​Controller

The trick it to add your URL as an activity item. Facebook (or twitter) will automatically interpret it as an attached link. Maybe want something like:

NSURL *linkURL = [NSURL URLWithString:@"https://www.facebook.com"];
NSString *linkDescription = @"New Game Name";
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[linkDescription, linkURL] applicationActivities:nil];
[navigationController presentViewController:activityViewController animated:YES completion:^{
    // ...
}];

P.S.: There's also a good talk around the subject here at stackoverflow

Community
  • 1
  • 1
nstefan
  • 187
  • 2
  • 8