这是相关代码:
// Create a like actionID<FBOpenGraphAction> action = (ID<FBOpenGraphAction>)[FBGraphObject graphObject];// link that like action to the restaurant object that we have created[action setobject:_objectID forKey:@"object"];// Post the action to Facebook[FBRequestConnection startForPostWithGraPHPath:@"me/og.likes" graphObject:action completionHandler:^(FBRequestConnection *connection,ID result,NSError *error) { __block Nsstring *alertText; __block Nsstring *alertTitle; if (!error) { // Success,the restaurant has been liked NSLog(@"Posted OG action,ID: %@",[result objectForKey:@"ID"]); alertText = [Nsstring stringWithFormat:@"Posted OG action,[result objectForKey:@"ID"]]; alertTitle = @"Success"; [[[UIAlertVIEw alloc] initWithTitle:alertTitle message:alertText delegate:self cancelbuttonTitle:@"OK!" otherbuttonTitles:nil] show]; } else { // An error occurred,we need to handle the error // See: https://developers.facebook.com/docs/ios/errors } }];
基本上我正在寻找这段代码的Swift翻译.在我的实际应用程序中,我将为游戏发布一个高分(不喜欢餐馆),但如果我有一些Swift可以使用,我应该能够弄清楚.
提前致谢!
解决方法 根据要求,这是我最终使用的方法.它没有使用FBOpenGraphAction,这使我在我的情况下实现起来要简单得多. (注意:您需要使用FBLoginVIEwDelegate):// Initialize variables let name = "Purple Square" let link = "https://itunes.apple.com/us/app/purple-square/ID942125866?ls=1&mt=8" let description = String(format: "I got %.1f. Can you beat me?",highscore) let picture = "https://www.dropBox.com/s/2nbaxai1arhqqrn/purpleSquareSplash.png?dl=1" let caption = "Exceptionally simple. Deceivingly hard. RIDiculously addictive." // Add variables to dictionary var dict = NSMutableDictionary() dict.setValue(name,forKey: "name") dict.setValue(caption,forKey: "caption") dict.setValue(description,forKey: "description") dict.setValue(link,forKey: "link") dict.setValue(picture,forKey: "picture") // Present the Feed dialog and post the story FBWebDialogs.presentFeedDialogModallyWithSession(nil,parameters: dict,handler: nil)总结
以上是内存溢出为你收集整理的ios – 如何在Swift中向Facebook发布故事?全部内容,希望文章能够帮你解决ios – 如何在Swift中向Facebook发布故事?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)