Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The way I implemented similar behavior is to put my session logic in a singleton. The singleton implements a completion handler that can be safely called by FB whenever the session changes. My completion handler then posts its own notifications for other controllers to observe as necessary.</p> <p>Let's assume you have a <code>MySession</code> singleton where you've defined some methods and notifications around FB auth. Your view controller logic would be something like:</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // observe MySession notifications [MySession.sharedSession addObserver:self]; } - (void)dealloc { // stop observing MySession notifications [MySession.sharedSession removeObserver:self]; } // this is a user action that requires FB auth - (void)someActionRequiringFacebookAuth { if (![MySession.sharedSession isLoggedIntoFacebook]) { self.postAuthAction = @selector(someActionRequiringFacebookAuth); [MySession.sharedSession loginToFacebook]; } else { // perform action } } // notification posted by MySession before a FB auth attempt - (void)mySessionWillAttemptFacebookAuth:(NSNotification *)notification { [self startLoadingAnimation]; } // notification posted by MySession if a FB auth attempt succeeds - (void)mySessionDidAuthWithFacebook:(NSNotification *)notification { [self stopLoadingAnimation]; if (self.postAuthAction) { [self performSelector:self.postAuthAction]; self.postAuthAction = nil; } } // notification posted by MySession if a FB auth attempt fails - (void)mySessionFacebookAuthDidFail:(NSNotification *)notification { [self stopLoadingAnimation]; // display error if desired self.postAuthAction = nil; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload