对象在 iOS 的打开图形共享对话框中消失

Posted

技术标签:

【中文标题】对象在 iOS 的打开图形共享对话框中消失【英文标题】:Object Disappears in Open Graph Share Dialogue for iOS 【发布时间】:2014-03-06 19:03:21 【问题描述】:

我正在尝试通过开放式图表分享对话为未通过 Facebook 登录的用户分享自定义故事。我的代码大部分是直接取自 Facebook 的示例,并进行了一些更改,因为我们没有任何图像。这似乎最初有效。该应用程序切换到具有正确格式预览的 Facebook。但是,预览消失了,“发布”按钮变灰。用户别无选择,只能取消并返回我们的应用程序。我还仔细检查了所有属性和命名空间。

NSString *urlDeepLink = [NSString stringWithFormat:@"http://www.appname.com?dropSpot='%@'&user='%@'&name='%@'&lat=%f&long=%f&rad=%d",place.objectId, [User currentUser].objectId, geospot.name, geospot.location.latitude, geospot.location.longitude, geospot.radius];

NSMutableDictionary<FBGraphObject> *object = [FBGraphObject openGraphActionForPost];
object[@"type"] =  @"appname:action";
object[@"title"] =  geospot.name;
object[@"description"] = place.detail;
object[@"url"] = urlDeepLink;

NSString *lat = [[NSNumber numberWithDouble:geospot.location.latitude]stringValue];
NSString *lng = [[NSNumber numberWithDouble:geospot.location.longitude]stringValue];

object[@"data" ] = @ @"location": @ @"latitude": lat, @"longitude": lng ;
object[@"fbsdk:create_object"] = @YES;

// create an Open Graph action
id<FBOpenGraphAction> action = (id<FBOpenGraphAction>)[FBGraphObject graphObject];
[action setObject:object forKey:@"action"];

// add expiration date for correct story tenses
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH:mm:ssZ"];
action[@"end_time"] = [dateFormatter stringFromDate:[NSDate date]];


// Check if the Facebook app is installed and we can present the share dialog
FBOpenGraphActionShareDialogParams *params = [[FBOpenGraphActionShareDialogParams alloc] init];
params.action = action;
params.actionType = @"appname:set";

// If the Facebook app is installed and we can present the share dialog
if([FBDialogs canPresentShareDialogWithOpenGraphActionParams:params]) 
    // Show the share dialog
    [FBDialogs presentShareDialogWithOpenGraphAction:action
                                          actionType:@"appname:set"
                                 previewPropertyName:@"action"
                                             handler:^(FBAppCall *call, NSDictionary *results, NSError *error) 
                                                 if(error) 
                                                     // There was an error
                                                     NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                                  else 
                                                     // Success
                                                     NSLog(@"result %@", results);
                                                 
                                             ];

    // If the Facebook app is NOT installed and we can't present the share dialog
 else 
    // FALLBACK: publish just a link using the Feed dialog
    // Put together the dialog parameters

    UIAlertView *alertUnableToPost = [[UIAlertView alloc]initWithTitle:@"Coudn't Post" message:@"We were unable to post your status to Facebook.  This could be because you don't have the Facebook app installed on your phone." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alertUnableToPost show];

    NSLog(@"Coudn't present share dialogue");

【问题讨论】:

【参考方案1】:

我明确地将“end_time”设置为当前日期(残留代码!)。删除该行可以使其正常工作。

【讨论】:

以上是关于对象在 iOS 的打开图形共享对话框中消失的主要内容,如果未能解决你的问题,请参考以下文章

FBSDKShareDialog 共享对话框未打开视频共享

为啥 Facebook iOS 的 feed 发布对话框在登录后消失?

mfc中我调用showwindow函数显示一个对话框,显示了,但是又瞬间消失了,这是啥情况啊?求解~~

打开软键盘时在顶部隐藏半个对话框

如何在 iOS 应用程序中添加共享对话框选项? [关闭]

cad能不能打开矢量数据