Skip to content

Commit

Permalink
Passing presenting view controller to RSTwitterEngine
Browse files Browse the repository at this point in the history
  • Loading branch information
MugunthKumar committed Mar 14, 2012
1 parent b0e80aa commit 74ae1a6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions TwitterDemo/Twitter/RSTwitterEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef void (^RSTwitterEngineStatusChangeHandler)(NSString *newStatus);
}

@property (nonatomic, copy) RSTwitterEngineStatusChangeHandler statusChangeHandler;
@property (assign, nonatomic) UIViewController *presentingViewController;

@property (readonly) NSString *screenName;

- (id)initWithStatusChangedHandler:(RSTwitterEngineStatusChangeHandler) handler;
Expand Down
8 changes: 5 additions & 3 deletions TwitterDemo/Twitter/RSTwitterEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ @implementation RSTwitterEngine

@synthesize webController = _webController;
@synthesize statusChangeHandler = _statusChangeHandler;
@synthesize presentingViewController = _presentingViewController;

#pragma mark - Read-only Properties

Expand Down Expand Up @@ -304,21 +305,22 @@ -(void) openURL:(NSURL*) url {

self.webController = [[WebViewController alloc] initWithURL:url];
self.webController.callbackURL = TW_CALLBACK_URL;
UIViewController *presentingViewController = [[[UIApplication sharedApplication] windows] objectAtIndex:0];
[presentingViewController presentModalViewController:self.webController animated:YES];

[self.presentingViewController presentModalViewController:self.webController animated:YES];

__unsafe_unretained RSTwitterEngine *weakSelf = self;

self.webController.authenticationCanceledHandler = ^{

__strong RSTwitterEngine *strongSelf = weakSelf;
[presentingViewController dismissModalViewControllerAnimated:YES];
[strongSelf.presentingViewController dismissModalViewControllerAnimated:YES];
[strongSelf cancelAuthentication];
};

self.webController.authenticationCompletedHandler = ^(NSURL* url) {

__strong RSTwitterEngine *strongSelf = weakSelf;
[strongSelf.presentingViewController dismissModalViewControllerAnimated:YES];
[strongSelf resumeAuthenticationFlowWithURL:url];
};
}
Expand Down
1 change: 1 addition & 0 deletions TwitterDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ - (void)viewDidLoad
self.statusLabel.text = newStatus;
}];

self.twitterEngine.presentingViewController = self;
// A right swipe on the status label will clear the stored token
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipedRight:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
Expand Down

0 comments on commit 74ae1a6

Please sign in to comment.