Facebook opens graph object with course LOBs in iOS

Anyone figured out 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 on Facebook. Duration and distance are displayed, but there is no track on the map. This means my problem is to implement the fitness: metric: location section. Any help?

Here is my source code, very simple. All I want is to add some more places to show the track. But NSDictionary does not allow 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];

      

+3


source to share


1 answer


I ran into this problem and managed to solve it. For this I mixed 2 articles: - the location model that you used https://developers.facebook.com/docs/opengraph/guides/fitness - the way to enter many points (the last paragraph about open objects of an open chart): https: // developers.facebook.com/docs/sharing/opengraph/ios

So, after the word metric, I determined the index [i]!



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

      

+3


source







All Articles