【问题标题】:Facebook open graph object with large course objects in iOSFacebook 在 iOS 中打开带有大型课程对象的图形对象
【发布时间】:2015-08-15 09:01:18
【问题描述】:

有人用 Facebook SDK 4.2.0 实现了健身课程的分享吗? 我有一个数组中的 CLLocation 对象的轨迹,并希望将其作为 Facebook 中的课程分享。显示持续时间和距离,但地图上没有轨迹。 这意味着,我的问题是实现 Fitness:metric:location 部分。 有什么帮助吗?

这是我的源代码,很简单。 我想要的只是添加更多位置来显示轨道。 但 NSDictionary 不允许同一个键有多个条目,因此无法将其添加到属性中。

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

NSDictionary *properties = @{
                             @"og:type": @"fitness.course",
                             @"og:title": @"YapYap Track",
                             @"og:description": @" ",
                             @"fitness:duration:value": appDelegate.actEvent.nDurationInSeconds,
                             @"fitness:duration:units": @"s",
                             @"fitness:distance:value": [NSNumber numberWithDouble:appDelegate.actEvent.nTracklengthInMeter.doubleValue/1000.0],
                             @"fitness:distance:units": @"km",
                             @"fitness:speed:value": [NSNumber numberWithDouble:appDelegate.actEvent.nTracklengthInMeter.doubleValue/appDelegate.actEvent.nDurationInSeconds.doubleValue],
                             @"fitness:speed:units": @"m/s",

                             @"fitness:metrics:location:latitude": appDelegate.actEvent.lat,
                             @"fitness:metrics:location:longitude": appDelegate.actEvent.lon,
                             };
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"fitness.walks";
[action setObject:object forKey:@"fitness:course"];
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"fitness:course";

[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

【问题讨论】:

  • 使用NSMutableDictionary 代替NSDictionary 是否有效? NSMutableDictionary 应该允许非唯一键;目前尚不清楚 FBSDKShareOpenGraphObject 将如何处理采用子类而不是 NSDictionary 但它可能没问题
  • 谢谢,伊吉。但与 NSMutableDictionary 相同,这也覆盖了 Fitness:metrics:location 条目。

标签: ios facebook share


【解决方案1】:

我遇到了这个问题并设法解决它。 为此,我混合了 2 篇文章: - 你使用的定位模型https://developers.facebook.com/docs/opengraph/guides/fitness - 输入多点的方式(关于开放图形复杂对象的最后一段):https://developers.facebook.com/docs/sharing/opengraph/ios

所以我在度量这个词之后定义了一个索引 [i] 并且它起作用了!

这是我的代码(在 swift 中,但在目标 C 中应该相同):

var properties: [String : AnyObject] = [
        "og:type": "fitness.course",
        "og:title": "Run",
        "og:description": "Run",
        "fitness:duration:value": run.duration,
        "fitness:duration:units": "s",
        "fitness:distance:value": run.distance,
        "fitness:distance:units": "m",
        "fitness:speed:value": run.speed,
        "fitness:speed:units": "m/s"
    ];

    var i = 0;

    for point in run.path {
        properties["fitness:metrics[\(i)]:location:latitude"] = point.latitude
        properties["fitness:metrics[\(i)]:location:longitude"] = point.longitude
        properties["fitness:metrics[\(i)]:location:altitude"] = point.altitude
        properties["fitness:metrics[\(i)]:timestamp"] = SRUtils.formatDate( NSDate(timeIntervalSinceReferenceDate: point.timestamp), format: "yyyy'-'MM'-'dd'T'HH':'mm'")
        i++;


    }

    let object = FBSDKShareOpenGraphObject(properties: properties);

【讨论】:

  • 我爱你!!! :) 谢谢! [\(i)] 将位置添加为数组!谢谢!!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-20
  • 1970-01-01
相关资源
最近更新 更多