Facebook open graph object with large course objects in iOS

纵饮孤独 提交于 2019-12-13 14:52:53

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/30581347/facebook-open-graph-object-with-large-course-objects-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!