格式化网址在Facebook帖子中显示为字符串

时间:2014-09-16 16:41:24

标签: ios objective-c nsstring string-formatting

我想在facebook上发布格式化为字符串的链接。请参阅以下相关代码:

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];

NSString *modifiedTitle = [NSString stringWithFormat:@"<a href= https://www.google.com> My App </a>"];
[params setObject:modifiedTitle 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)
     {
         //showing an alert for failure
         NSLog(@"ERROR in posting image to Facebook");
     }
     else
     {
         //showing an alert for success
         NSLog(@"Result after posting image successfully = %@",result);
     }
     // button.enabled = YES;
 }];

消息显示为:

<a href= https://www.google.com> My App </a>

而不是

My App

1 个答案:

答案 0 :(得分:1)

首先,确保您使用复制方法在startWithGraph ...方法中发布一个immutable字典:

NSDictionary* paramsImmutable = params.copy;
[FBRequestConnection startWithGraphPath:@"me/photos"
                         parameters:paramsImmutable
                         HTTPMethod:@"POST"
                  completionHandler:^(FBRequestConnection *connection,
                                      id result,
                                      NSError *error)

这样,在方法的生命周期内,您无法对该对象进行任何更改。

接下来,您的参数是否包括网址周围的任何引号?即。

NSString *modifiedTitle = @"<a href='https://www.google.com'>My App</a>";

这只是一个开始。