Facebook在iOS中使用大型课程对象打开图形对象 [英] Facebook open graph object with large course objects in iOS

查看:125
本文介绍了Facebook在iOS中使用大型课程对象打开图形对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人通过Facebook SDK 4.2.0实现了健身课程的分享?
我有一个数组中的CLLocation对象的跟踪,并希望将其作为Facebook的课程分享。显示持续时间和距离,但地图上没有轨迹。
这意味着我的问题是实现健身度量:度量:位置部分。
任何帮助?



这是我的源代码,非常简单。
我想要的是添加更多的位置来显示曲目。
但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];


解决方案

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



所以我定义了一个索引[i],在这个指标之后,它工作!



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

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

var i = 0;

在run.path中的点{
属性[fitness:metrics [\(i)]:location:latitude] = point.latitude
属性[fitness :metrics [\(i)]:location:longitude] = point.longitude
属性[fitness:metrics [\(i)]:location:altitude] = point.altitude
属性[fitness:metrics [\(i)]:timestamp] = SRUtils.formatDate(NSDate(timeIntervalSinceReferenceDate:point.timestamp),格式:yyyy' - 'MM' - 'dd'T'HH' mm')
i ++;


}

let object = FBSDKShareOpenGraphObject(properties:properties);


Has anyone realized a share for a fitness course with Facebook SDK 4.2.0? I have a track of CLLocation objects in an array and would like to share this as a course in Facebook. Duration and distance is shown, but no track on the map. That means, my problem is to realize the fitness:metric:location section. Any help?

Here is my source code, very simple. All I want is adding some more locations to show the track. But NSDictionary is not allowing multiple entries for the same key, so adding it to properties is not possible.

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];

解决方案

I encounter this issue and manage to solve it. To do that I mixed 2 articles : - the location model you used https://developers.facebook.com/docs/opengraph/guides/fitness - the way you enter many points (last paragraph about open graph complex objects) : https://developers.facebook.com/docs/sharing/opengraph/ios

So I defined an index [i] after the word metrics and it worked !

Here is my code (in swift, but it should be the same in 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);

这篇关于Facebook在iOS中使用大型课程对象打开图形对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆