Permalink
Browse files

Unregister as observer on application launch notification in notifica…

…tion block
  • Loading branch information...
1 parent f98e76f commit 6c9d8aeffeaf10e5b73386e1e739714185d8b0ca Erik Sundin committed Mar 6, 2013
Showing with 24 additions and 17 deletions.
  1. +24 −17 AFOAuth1Client/AFOAuth1Client.m
@@ -257,23 +257,30 @@ - (void)authorizeUsingOAuthWithRequestTokenPath:(NSString *)requestTokenPath
{
[self acquireOAuthRequestTokenWithPath:requestTokenPath callback:callbackURL accessMethod:(NSString *)accessMethod success:^(AFOAuth1Token *requestToken) {
__block AFOAuth1Token *currentRequestToken = requestToken;
- [[NSNotificationCenter defaultCenter] addObserverForName:kAFApplicationLaunchedWithURLNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) {
- NSURL *url = [[notification userInfo] valueForKey:kAFApplicationLaunchOptionsURLKey];
-
- currentRequestToken.verifier = [AFParametersFromQueryString([url query]) valueForKey:@"oauth_verifier"];
-
- [self acquireOAuthAccessTokenWithPath:accessTokenPath requestToken:currentRequestToken accessMethod:accessMethod success:^(AFOAuth1Token * accessToken) {
- self.accessToken = accessToken;
-
- if (success) {
- success(accessToken);
- }
- } failure:^(NSError *error) {
- if (failure) {
- failure(error);
- }
- }];
- }];
+
+ __block id applicationLaunchNotificationObserver = [[NSNotificationCenter defaultCenter]
+ addObserverForName:kAFApplicationLaunchedWithURLNotification
+ object:nil
+ queue:[NSOperationQueue mainQueue]
+ usingBlock:^(NSNotification *notification) {
+
+ [[NSNotificationCenter defaultCenter] removeObserver:applicationLaunchNotificationObserver];
+ NSURL *url = [[notification userInfo] valueForKey:kAFApplicationLaunchOptionsURLKey];
+
+ currentRequestToken.verifier = [AFParametersFromQueryString([url query]) valueForKey:@"oauth_verifier"];
+
+ [self acquireOAuthAccessTokenWithPath:accessTokenPath requestToken:currentRequestToken accessMethod:accessMethod success:^(AFOAuth1Token * accessToken) {
+ self.accessToken = accessToken;
+
+ if (success) {
+ success(accessToken);
+ }
+ } failure:^(NSError *error) {
+ if (failure) {
+ failure(error);
+ }
+ }];
+ }];
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
[parameters setValue:requestToken.key forKey:@"oauth_token"];

0 comments on commit 6c9d8ae

Please sign in to comment.