I have downloaded a Twitter kit framework and added code to login with Twitter. But, I don't want Login button look like that. I want a custom button for Login. Can I do that ? I only want to use this framework as this also leverages with iOS system account.
As per the document :
Add the code in your button press :
[[Twitter sharedInstance] logInWithCompletion:^
(TWTRSession *session, NSError *error) {
if (session) {
NSLog(@"signed in as %@", [session userName]);
} else {
NSLog(@"error: %@", [error localizedDescription]);
}
}];
Twitter.sharedInstance().logInWithCompletion {
(session, error) -> Void in
if (session != nil) {
println("signed in as \(session.userName)");
} else {
println("error: \(error.localizedDescription)");
}
}
Yes,you can do customize your Twitter login button.
Just add your UIButton in your storyboard's desired View controller. Select it and open the identity inspector, now in the Class textfield, enter "TWTRLogInButton" after that create a property.
You will create something like this:-
@property (nonatomic,strong) IBOutlet TWTRLogInButton *customTwitterButton;
After that you can use it or implement it in your viewDidLoad
method like this:-
self.customTwitterButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
// do operations as per your wish
}];
Twitter has provided a separate method for Sign In in the documentation. Create your custom button in xib or storyboard, give it a selector and add a method for twitter login. Here is an example:
- (IBAction)btnTwitterLogin_pressed:(id)sender
{
[[Twitter sharedInstance] logInWithCompletion:^
(TWTRSession *session, NSError *error) {
if (session) {
NSLog(@"%@", [session userID]);
NSLog(@"%@", [session userName]);
NSLog(@"%@", [session authToken]);
NSLog(@"%@", [session authTokenSecret]);
} else {
NSLog(@"Error: %@", [error localizedDescription]);
}
}];
}
Hope it helps others too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With