Facebook 在 iOS 中使用大型课程对象打开图形对象

2024-01-07

有人用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];

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

因此,我在“metrics”一词之后定义了一个索引 [i],它起作用了!

这是我的代码(在 swift 中,但在 Objective 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Facebook 在 iOS 中使用大型课程对象打开图形对象 的相关文章

随机推荐