Twitter LogIn with Fabric in Swift?

LogIn with Twitter feature means authentication with Twitter, This tutorials provide to Twitter LogIn with the use of the Twitter of Fabric, So you have to installed Fabric. if you haven't installed Fabric then How to installed Fabric in Xcode.




Twitter API keys are automatically generate from Fabric When you installed Twitter. The Consumer Key and Consumer Secrete in info.plist file, So user haven't  make apps for twitter manually and added the key in code. The twitter checked of system login account. if user doesn't login then present login of the twitter for authentication. and saves account to iOS system account. 

Two way to Login with Twitter :

1. LogIn with Twitter Button : TwitterKit have default button known as TWTRLogInButton class.
let logInButton = TWTRLogInButton { (session, error) in
            
            if let unwrappedSession = session {
                print(unwrappedSession.userID)
                print(unwrappedSession.userName)
                print(unwrappedSession.authToken)
                print(unwrappedSession.authTokenSecret)
                
            } else {
                NSLog("Login error: %@", error!.localizedDescription);
            }
        }
        
        // TODO: Change where the log in button is positioned in your view
        logInButton.center = self.view.center
        self.view.addSubview(logInButton)

2. Login Method : You can make one custom button for login and put the Login method on click event for twitter Authentication.
Twitter.sharedInstance().logInWithCompletion {
            (session, error) -> Void in
            if (session != nil) {
                
                print(session!.userID)
                print(session!.userName)
                print(session!.authToken)
                print(session!.authTokenSecret)
                
            }else {
                print("Not Login")
            }
        }
 Thanks.


Twitter LogIn with Fabric in Swift? Twitter LogIn with Fabric in Swift? Reviewed by KIRIT MODI on 05:58:00 Rating: 5

No comments:

Powered by Blogger.