Ios 格式化url以在facebook帖子中显示为字符串
我试图在facebook上发布一个字符串格式的链接。请参阅下面的相关代码:Ios 格式化url以在facebook帖子中显示为字符串,ios,objective-c,nsstring,string-formatting,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:modifiedTitl
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;
}];
首先,确保您正在向startWithGraph中发布一个不可变字典。。。方法通过使用复制方法:
NSDictionary* paramsImmutable = params.copy;
[FBRequestConnection startWithGraphPath:@"me/photos"
parameters:paramsImmutable
HTTPMethod:@"POST"
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
这样,在方法的生命周期内,您就不会担心该对象的任何更改
接下来,您的参数是否在url周围包含任何类型的引号?即
NSString *modifiedTitle = @"<a href='https://www.google.com'>My App</a>";
NSString*modifiedTitle=@”;
这只是一个开始。我让字典不可变,就像你在上面所做的那样,然后我开始在发布时使用字典。我刚刚用错误日志更新了代码,
error in posting image to Facebook
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>";