Permalink
Browse files

Passing presenting view controller to RSTwitterEngine

  • Loading branch information...
1 parent b0e80aa commit 74ae1a6cab673b9b902ebe980bc9ea25c288f1de @MugunthKumar committed Mar 14, 2012
Showing with 8 additions and 3 deletions.
  1. +2 −0 TwitterDemo/Twitter/RSTwitterEngine.h
  2. +5 −3 TwitterDemo/Twitter/RSTwitterEngine.m
  3. +1 −0 TwitterDemo/ViewController.m
@@ -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;
@@ -49,6 +49,7 @@ @implementation RSTwitterEngine
@synthesize webController = _webController;
@synthesize statusChangeHandler = _statusChangeHandler;
+@synthesize presentingViewController = _presentingViewController;
#pragma mark - Read-only Properties
@@ -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];
};
}
@@ -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;

0 comments on commit 74ae1a6

Please sign in to comment.