facebookarchive / account-kit-samples-for-ios

Samples for the account kit product on ios.
43 stars 26 forks source link

phoneNumber AKFPhoneNumber? nil #21

Closed Bobby122333 closed 5 years ago

Bobby122333 commented 5 years ago

Hi,

The code is returning nil for the phone number, it was working yesterday. Account Id is being fetching properly. I am using SMS authentication . Running this on Xcode 10.1 Code snippet below: if accountKit == nil { //specify AKFResponseType.AccessToken self.accountKit = AKFAccountKit(responseType: AKFResponseType.accessToken) accountKit.requestAccount{ (account, error) -> Void in

                    let accountID = account?.accountID
                    let phoneNumber = account?.phoneNumber
robtimp commented 5 years ago

If I understand correctly, you're attempting to use the requestAccount method to log in, but it's actually meant for getting information about the current account after logging in.

Try something like this:

func startLogin() {
    if accountKit == nil {
        self.accountKit = AKFAccountKit(responseType: AKFResponseType.accessToken)
    }

    let viewController = accountKit.viewControllerForPhoneLogin(with: nil, state: nil)
    viewController.delegate = self
    present(viewController, animated: true, completion: nil)
}

// AKFViewControllerDelegate

func viewController(_ viewController: UIViewController & AKFViewController,
                    didCompleteLoginWith accessToken: AccessToken, state: String) {
    // Now we have a valid access token and can call requestAccount
    accountKit.requestAccount { (account, error) in
        let accountID = account?.accountID
        let phoneNumber = account?.phoneNumber
        ...
    }
}

Please let me know if you need any further clarification or help.

anhhtbk commented 5 years ago

@robtimp After login, I request account to get phone number, but phonNumber still nil.

///  I use authorizationCode not accessToken
accountKit = AccountKit(responseType: .authorizationCode)
/////
func viewController(_ viewController: UIViewController & AKFViewController, didCompleteLoginWith code: String, state: String) {
        Log.debug("didComplteLoginWith code:", values: [code, "state:", state])
        accountKit.requestAccount { (account, error) in
            Log.debug("phoneNumber: ", values: [account?.phoneNumber?.phoneNumber]) // ==>> nil
        }
}
robtimp commented 5 years ago

@anhhtbk

A valid access token is required to use the requestAccount method, so this isn’t possible with the authorizationCode response type.