Facebook login via social framework in ios

后端 未结 3 928
别那么骄傲
别那么骄傲 2021-01-31 05:48

I\'m new with iOS development. I have to integrate Facebook login in my iOS app, as user logs in it fetches all the info and navigates it to home screen. I have done this via Fa

3条回答
  •  孤独总比滥情好
    2021-01-31 06:24

    Facebook login using Accounts and social framework (swift)

    var facebookAccount: ACAccount?
    
            let options: [NSObject : AnyObject] = [ACFacebookAppIdKey: "YOUR_FACEBOOK_API_KEY", ACFacebookPermissionsKey: ["publish_stream","publish_actions"],ACFacebookAudienceKey:ACFacebookAudienceFriends]
            let accountStore = ACAccountStore()
            let facebookAccountType = accountStore.accountTypeWithAccountTypeIdentifier(ACAccountTypeIdentifierFacebook)
    
                accountStore.requestAccessToAccountsWithType(facebookAccountType, options: options) { (granted, error) -> Void in
                    if granted
                    {
                        let accounts = accountStore.accountsWithAccountType(facebookAccountType)
                        self.facebookAccount = accounts.last as? ACAccount
                        let accountsArray=accountStore.accountsWithAccountType(facebookAccountType) as NSArray
    
                        self.facebookAccount=accountsArray.lastObject as? ACAccount
                        var dict:NSDictionary
                        dict=NSDictionary()
    
                        dict=self.facebookAccount!.dictionaryWithValuesForKeys(["properties"])
                        let properties:NSDictionary=dict["properties"] as! NSDictionary
                        print("facebook Response is-->:%@",properties)
                    }
                    else
                    {
                        if error.code == Int(ACErrorAccountNotFound.rawValue) {
                            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                                self.displayAlert("There is no Facebook accounts configured. you can add or created a Facebook account in your settings.")
                            })
                        } else {
                            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                                self.displayAlert("Permission not granted For Your Application")
                            })
                        }
    
                    }
                }
    

提交回复
热议问题