Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Unregister as observer on application launch notification in notifica…
Browse files Browse the repository at this point in the history
…tion block
  • Loading branch information
Erik Sundin committed Mar 6, 2013
1 parent f98e76f commit 6c9d8ae
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions AFOAuth1Client/AFOAuth1Client.m
Expand Up @@ -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"];
Expand Down

0 comments on commit 6c9d8ae

Please sign in to comment.