使用 graph api 在 Facebook 上发布高分
编辑:10-10-9
我认为当 JSON 库尝试解析
[NSString stringWithFormat:@"%d weeks",[components week]];
我如何格式化它以便 JSON 可以解析它时,应用程序崩溃了?
这是 JSON 代码行
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"api_key",
@"Share on Facebook", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",
nil];
任何人都可以向我指出如何执行此操作的教程吗?我可以轻松地在下面的代码块中发布静态文本,但我无法将 NSString
与动态数据集成,它不会显示在 Facebook 帖子附件部分。
NSDictionary *attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"Testing", @"name",
@"testing2", @"caption",
[NSString stringWithFormat:@"%d weeks",[components week]], @"description"//Xcode says components undeclared
//highscore, @"description", //here's the problem, highscore is the NSString variable.
@"http://testing.com/", @"href", nil];
更新: 问题是我使用的字符串来自 2 周之差的时间间隔,输出是 [components week]
然后 xcode 告诉我 Components 是一个未声明的变量,
[NSString stringWithFormat:@"%d weeks",[components week]]
这是整个日期我从以下位置获取上面字符串的代码块:
NSString *dateStr = @"20100716";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *startDate = [dateFormat dateFromString:dateStr];
NSDate *endDate = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSWeekCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags
fromDate:startDate
toDate:endDate options:0];
NSInteger weeks = [components week];
NSInteger days = [components day];
Edit: 10-9-10
I think the app is crashing when the JSON library tries to parse the
[NSString stringWithFormat:@"%d weeks",[components week]];
How would i format it so that JSON can parse it?
Here's the JSON code line
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"api_key",
@"Share on Facebook", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",
nil];
Can anyone point me to a tutorial on how to do this? I can easily post the static text in the code block below but i can't integrate an NSString
with dynamic data, it doesn't show up on the Fb post attachment section.
NSDictionary *attachment = [NSDictionary dictionaryWithObjectsAndKeys:
@"Testing", @"name",
@"testing2", @"caption",
[NSString stringWithFormat:@"%d weeks",[components week]], @"description"//Xcode says components undeclared
//highscore, @"description", //here's the problem, highscore is the NSString variable.
@"http://testing.com/", @"href", nil];
Update:
the problem is the string i'm using is from a time interval of the difference of 2 weeks and the out put is [components week]
and then xcode tells me components is an undeclared variable
[NSString stringWithFormat:@"%d weeks",[components week]]
here's the whole date code block that i get the string above from:
NSString *dateStr = @"20100716";
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyyMMdd"];
NSDate *startDate = [dateFormat dateFromString:dateStr];
NSDate *endDate = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSUInteger unitFlags = NSWeekCalendarUnit | NSDayCalendarUnit;
NSDateComponents *components = [gregorian components:unitFlags
fromDate:startDate
toDate:endDate options:0];
NSInteger weeks = [components week];
NSInteger days = [components day];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试 stringWithFormat
[NSString stringWithFormat:@"%@", highscore];
而不是 highscoreTry stringWithFormat
[NSString stringWithFormat:@"%@", highscore];
instead of highscore