2014-09-02 102 views
0

我是新来的使用Open Graph,并没有看到在Facebook教程或文档的说明如何做到这一点。这是在Xcode 6如何自定义Open Graph故事?

在iOS 8做我想我的一句话要说

I just got a score of *350*! Can you beat it? 

但是不知道怎么把我的self.score将其添加到打开的图形故事!

我没有代码可以显示,因为来自Facebook的教程已过时。如果任何人都可以请给我提供更好的代码,这些代码不会在定制Open Graph(或更好的解决方案)上发布上面的代码时出错,我将非常感激。

回答

0

由于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); 
                 } 
                } 
               } 
              }]; 

}