快速使用facebook ios sdk获取用户的位置信息

问题描述:

我找不到任何有关在swift和xcode 6中获取用户位置信息的信息

I couldn't find any info about getting user's location info in swift and xcode 6

我尝试了

var fbcity = user.objectForKey("location")
        var fbcountry = user.objectForKey("country")

但是没有用.

有什么想法要实现吗?

也许您可以向我们提供更多信息,例如您正在使用哪个Facebook SDK,FBSDKGraphRequest必须返回什么参数user.请注意,当您发送用户配置文件的图形请求时,没有关于国家的特定信息,即用户节点中的location字段.它将返回子字段:idname,其中名称为

Perhaps you could supply us with a little more information, e.g. which Facebook SDK you are using and what parameters FBSDKGraphRequest has to return user. Note that there is no specific information about country, the location field in the user node when your send a graph request for the user profile. It will return the subfields: id and name, where name is

使用最新的Facebook iOS SDK 4.0,您可以执行以下操作:

With the latest Facebook iOS SDK 4.0 you can do something like:

override func viewDidLoad() {
    super.viewDidLoad()

    self.loginView.delegate = self

    if FBSDKAccessToken.currentAccessToken() != nil {
        fetchUserData()
    } else {
        loginView.readPermissions = ["public_profile", "email", "user_friends"]
    }       
}

func fetchUserData() {
    let graphRequest: FBSDKGraphRequest = FBSDKGraphRequest(graphPath: "me", parameters: nil)
    graphRequest.startWithCompletionHandler({ (connection, result, error) -> Void in                
        if error != nil {
             // Process error
             println("Error: \(error)")
        } else {              
             let location: NSDictionary! = result.valueForKey("location") as NSDictionary
             let city: NSString = location.valueForKey("name") as NSString                   
        }
    })
}

更详细的信息可以在 Facebook Graph API用户页面上找到

More detailed info can be found on Facebook Graph API User page.