由于Facebook代码错误,我会解释我是如何找到一种方法来完成它,然后发布完整的代码。
我忘了打开图的想法,并决定只发布一个简单的条件字符串触发一个按钮。从那里我用Facebook的代码here,只使用回退作为“共享对话框”上面,它不完全工作。
从那里我只是用[NSString stringWithFormat:%@%@%@,string1,self.score,string2];
下面是示例代码(修改为通用他人):
-(IBAction)facebookShare:(id)sender {
//Set Variables
int scoreText
int highScoreText
//Format the description
NSString *description;
NSString *t1 = @"I just got a score of ";
NSString *t1Alt = @"I just got a new high score of ";
NSString *t2 = @"! Can you beat it?";
if (self.newHigh == NO){
description = [NSString stringWithFormat:@"%@%@%@",t1,scoreText,t2];
} else if (self.newHigh == YES){
description = [NSString stringWithFormat:@"%@%@%@",t1Alt,highScoreText,t2];
}
// Put together the dialog parameters
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Edit Me", @"name",
@"Edit Me", @"caption",
description, @"description",
@"http://Edit.Me.Too/", @"link",
@"http://And.Me.Too/", @"picture",
nil];
/* * * * * * * * * * * DO NOT EDIT BELOW THIS LINE * * * * * * * * * * * *
* *
* *
* From here on, this shows share screen *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
[FBWebDialogs presentFeedDialogModallyWithSession:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// An error occurred, we need to handle the error
// See: https://developers.facebook.com/docs/ios/errors
NSLog(@"Error publishing story: %@", error.description);
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// Handle the publish feed callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"post_id"]) {
// User cancelled.
NSLog(@"User cancelled.");
} else {
// User clicked the Share button
NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
NSLog(@"result %@", result);
}
}
}
}];
}