HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – 如何在Swift中向Facebook发布故事?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我到处搜索,我无法找到任何关于如何在 Swift中向Facebook发帖的文档.我试图将此代码Obj-C转换为Swift,但我没有取得多大进展(我不知道如何在Obj-C中编码).我希望在Swift: https://developers.facebook.com/docs/ios/graph#postingstory中完成类似的事情

这是相关代码

// Create a like action
id<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发布故事?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。