Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS customHandlerClass example from README #56

Closed
zwacky opened this issue Oct 15, 2019 · 1 comment
Closed

iOS customHandlerClass example from README #56

zwacky opened this issue Oct 15, 2019 · 1 comment

Comments

@zwacky
Copy link

zwacky commented Oct 15, 2019

Hey Michael, first of all thank you for creating and maintaining this great plugin!

I was following the docs to create the iOS Facebook login and had problems with the YourIOsFacebookOAuth2Handler class. I got following two issues and did some changes to make them work again:

Value of type 'AccessToken' has no member 'authenticationToken':

...
if let accessToken = AccessToken.current {
    success(accessToken.authenticationToken)
} else {
...

changed to

if let accessToken = AccessToken.current {
    success(accessToken.tokenString)
} else {
...

Use of unresolved identifier 'ReadPermission'

...
self.loginManager!.logIn(readPermissions: [ ReadPermission.publicProfile ],
...

changed to

self.loginManager!.logIn(permissions: [ Permission.publicProfile ],

I'm new to Capacitor, I'm new to swift. If I'd be more confident in it would have turned into a PR right away. 🙈
What do you think?

@moberwasserlechner
Copy link
Collaborator

moberwasserlechner commented Oct 16, 2019

Hey,

thanks for the reminder :)

I stumbled on this myself but forgot to update the README when I updated to latest version of Facebook pods.

PodFile entry:

  # Add your Pods here
  pod 'FacebookCore'
  pod 'FacebookLogin'

My working handler looks like that

import Foundation
import FacebookCore
import FacebookLogin
import Capacitor
import ByteowlsCapacitorOauth2

@objc class FBOAuth2Handler: NSObject, OAuth2CustomHandler {
    
    var loginManager: LoginManager?;
    
    required override init() {
    }
    
    func getAccessToken(viewController: UIViewController, call: CAPPluginCall, success: @escaping (String) -> Void, cancelled: @escaping () -> Void, failure: @escaping (Error) -> Void) {
        
        if let accessToken = AccessToken.current {
            success(accessToken.tokenString)
        } else {
            DispatchQueue.main.async {
                if self.loginManager == nil {
                    self.loginManager = LoginManager()
                }
            
                self.loginManager!.logIn(permissions: [ .publicProfile ],
                                         viewController: viewController, completion: { loginResult in
                                            switch loginResult {
                                            case .failed(let error):
                                                failure(error)
                                            case .cancelled:
                                                cancelled()
                                            case .success(_, _, let accessToken):
                                                success(accessToken.tokenString)
                                            }
                })
            }
        }
    }
    
    func logout(call: CAPPluginCall) -> Bool {
        self.loginManager?.logOut()
        return true
    }
}

Hope this helps and I will update the README soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants