Permalink
Browse files

Fixed a crashing bug

  • Loading branch information...
1 parent 387bc2c commit 32aa4eeff6cec6cf8c8bf64e92717f90e6444da5 @MugunthKumar committed Mar 14, 2012
Showing with 35 additions and 20 deletions.
  1. +13 −2 Twitter/RSTwitterEngine.m
  2. +22 −18 TwitterDemo/ViewController.m
View
@@ -185,7 +185,8 @@ -(void) tryiOS5TwitterAccountAuthOnCompletion:(void (^)(void)) completionBlock {
ACAccountStore *account = [[ACAccountStore alloc] init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
-
+ self.statusChangeHandler(@"Authenticating...");
+
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{
if (!granted) {
@@ -200,6 +201,7 @@ -(void) tryiOS5TwitterAccountAuthOnCompletion:(void (^)(void)) completionBlock {
if([arrayOfAccounts count] == 1) {
self.iOS5TwitterAccount = [arrayOfAccounts objectAtIndex:0];
+ _screenName = self.iOS5TwitterAccount.username;
completionBlock();
return;
} else {
@@ -210,13 +212,16 @@ -(void) tryiOS5TwitterAccountAuthOnCompletion:(void (^)(void)) completionBlock {
[buttonsArray addObject:((ACAccount*)obj).username];
}];
+ self.statusChangeHandler(@"Waiting for user authorization...");
[UIActionSheet actionSheetWithTitle:@"Choose your Twitter account"
message:nil
buttons:buttonsArray
showInView:self.presentingViewController.view
onDismiss:^(int buttonIndex) {
self.iOS5TwitterAccount = [arrayOfAccounts objectAtIndex:buttonIndex];
+ _screenName = self.iOS5TwitterAccount.username;
+
completionBlock();
} onCancel:^{
@@ -324,6 +329,11 @@ - (void)forgetStoredToken
#pragma mark - Public Methods
+-(BOOL) isAuthenticated {
+
+ if(self.iOS5TwitterAccount) return YES;
+ else return [super isAuthenticated];
+}
- (void)sendTweet:(NSString *)tweet withCompletionBlock:(RSTwitterEngineCompletionBlock)completionBlock
{
@@ -347,13 +357,14 @@ - (void)sendTweet:(NSString *)tweet withCompletionBlock:(RSTwitterEngineCompleti
TWRequest *postRequest = [[TWRequest alloc] initWithURL:
[NSURL URLWithString:@"http://api.twitter.com/1/statuses/update.json"]
- parameters:[NSDictionary dictionaryWithObject:@"abc"
+ parameters:[NSDictionary dictionaryWithObject:tweet
forKey:@"status"] requestMethod:TWRequestMethodPOST];
[postRequest setAccount:self.iOS5TwitterAccount];
[postRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
NSLog(@"Twitter response, HTTP response: %i", [urlResponse statusCode]);
+ completionBlock(error);
}];
} else {
// Fill the post body with the tweet
@@ -115,31 +115,35 @@ - (IBAction)sendTweet:(id)sender
self.sendButton.enabled = NO;
[self.twitterEngine sendTweet:self.textView.text withCompletionBlock:^(NSError *error) {
+
+ dispatch_async(dispatch_get_main_queue(), ^{
if (error) {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
- message:[error localizedDescription]
- delegate:nil
- cancelButtonTitle:@"Dismiss"
- otherButtonTitles:nil];
- [alert show];
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
+ message:[error localizedDescription]
+ delegate:nil
+ cancelButtonTitle:@"Dismiss"
+ otherButtonTitles:nil];
+ [alert show];
} else {
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"QuickTweet!"
- message:@"Tweet posted successfully!"
- delegate:nil
- cancelButtonTitle:@"Dismiss"
- otherButtonTitles:nil];
- [alert show];
-
- self.textView.text = @"";
+ UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"QuickTweet!"
+ message:@"Tweet posted successfully!"
+ delegate:nil
+ cancelButtonTitle:@"Dismiss"
+ otherButtonTitles:nil];
+ [alert show];
+
+ self.textView.text = @"";
}
self.sendButton.enabled = YES;
-
+
if (self.twitterEngine.isAuthenticated) {
- self.statusLabel.text = [NSString stringWithFormat:@"Signed in as @%@.", self.twitterEngine.screenName];
+ self.statusLabel.text = [NSString stringWithFormat:@"Signed in as @%@.", self.twitterEngine.screenName];
} else {
- self.statusLabel.text = @"Not signed in.";
- }
+ self.statusLabel.text = @"Not signed in.";
+ }
+ });
+
}];
}
}

0 comments on commit 32aa4ee

Please sign in to comment.