在 Swift 中调用 Facebook 代表

2023-09-12移动开发问题
1

本文介绍了在 Swift 中调用 Facebook 代表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

如何使用 Swift 调用 Facebook 代表?Xcode 不自动补全,不知道怎么用.

How can I call the Facebook delegates using Swift? Xcode doesn't autocomplete and I don't know how use it.

import UIKit

class ViewController: UIViewController,FBLoginViewDelegate {

    @IBOutlet var fbLoginView : FBLoginView

    override func viewDidLoad() {
        super.viewDidLoad()

        self.fbLoginView.delegate = self
        self.fbLoginView.readPermissions = ["public_profile", "email", "user_friends"]

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    // Facebook Delegates



}

推荐答案

我将给出一个示例翻译并解释它,以便您能够翻译其余的委托方法:

I will give one example translation and explain it so that you should be able to translate the rest of the delegate methods:

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user: (id<FBGraphUser>)user;

  1. 方法名称以loginViewFetchedUserInfo"开头.保持不变
  2. 参数是FDBLoginView"类型的指针,因为它可以为nil,所以将被转换为FBLoginView 类型的可选项.约定是使其成为隐式展开的可选,因此它将成为 FBLoginView!
  3. 在 Swift 中,协议本身就是类型,因此用户参数将变成简单的 FBGraphUser.
  4. 假定 swift 方法中的第一个参数只是一个内部名称,因此参数可以命名为任何名称,但为了保持一致性,我们将其命名为:loginView"
  5. swift 方法中的第二个参数被假定为内部和外部.在 Objective-C 版本中,它们恰好是相同的,所以我们可以简单地使用它一次,Swift 会使其成为内部和外部名称

这给我们留下了这个翻译:

This leaves us with this translation:

func loginViewFetchedUserInto(loginView : FBLoginView!, user: FBGraphUser)

这篇关于在 Swift 中调用 Facebook 代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

突出显示朗读文本(在 iPhone 的故事书类型应用程序中)
Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))...
2024-08-12 移动开发问题
9

游戏中心 facebook 喜欢
Game center facebook like(游戏中心 facebook 喜欢)...
2024-08-12 移动开发问题
3

从 Documents 目录存储和读取文件 iOS 5
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)...
2024-08-12 移动开发问题
9

如何在使用 cocos2d 的 iphone 应用程序中使用 MYSQL 数据库连接?
How can i use MYSQL database connection in iphone application useing cocos2d?(如何在使用 cocos2d 的 iphone 应用程序中使用 MYSQL 数据库连接?)...
2024-08-12 移动开发问题
5

在 cocos2d 中平滑拖动一个 Sprite - iPhone
Smoothly drag a Sprite in cocos2d - iPhone(在 cocos2d 中平滑拖动一个 Sprite - iPhone)...
2024-08-12 移动开发问题
10