Skip to content

Commit

Permalink
iOS SDK:Facebook delegate fbDidNotLogin add a parameter to check if u…
Browse files Browse the repository at this point in the history
…ser cancel and address several other issue
  • Loading branch information
Yujuan Bao committed Sep 1, 2010
1 parent fb5b523 commit 57818a0
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
6 changes: 3 additions & 3 deletions sample/DemoApp/Classes/DemoAppViewController.m
Expand Up @@ -45,7 +45,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
* Set initial view
*/
- (void) viewDidLoad {
_facebook = [[[[Facebook alloc] init] autorelease] retain];
_facebook = [[Facebook alloc] init];
[self.label setText:@"Please log in"];
_getUserInfoButton.hidden = YES;
_getPublicInfoButton.hidden = YES;
Expand Down Expand Up @@ -200,7 +200,7 @@ -(void) fbDidLogin {
/**
* Callback for facebook did not login
*/
- (void)fbDidNotLogin {
- (void)fbDidNotLogin:(BOOL)cancelled {
NSLog(@"did not login");
}

Expand Down Expand Up @@ -240,7 +240,7 @@ - (void)request:(FBRequest*)request didFailWithError:(NSError*)error{
* The resulting object may be a dictionary, an array, a string, or a number, depending
* on thee format of the API response.
*/
- (void)request:(FBRequest*)request didLoad:(id)result{
- (void)request:(FBRequest*)request didLoad:(id)result {
if ([result isKindOfClass:[NSArray class]]) {
result = [result objectAtIndex:0];
}
Expand Down
2 changes: 1 addition & 1 deletion sample/theRunAround/Classes/mainViewController.m
Expand Up @@ -74,7 +74,7 @@ - (void)viewDidLoad {
_session = [[Session alloc] init];
_facebook = [[_session restore] retain];
if (_facebook == nil) {
_facebook = [[[[Facebook alloc] init] autorelease] retain];
_facebook = [[Facebook alloc] init];
_fbButton.isLoggedIn = NO;
_addRunButton.hidden = YES;
[self.view addSubview:self.logoutView];
Expand Down
2 changes: 1 addition & 1 deletion src/FBLoginDialog.h
Expand Up @@ -41,7 +41,7 @@

- (void) fbDialogLogin:(NSString *) token expirationDate:(NSDate *) expirationDate;

- (void) fbDialogNotLogin;
- (void) fbDialogNotLogin:(BOOL) cancelled;

@end

Expand Down
10 changes: 5 additions & 5 deletions src/FBLoginDialog.m
Expand Up @@ -59,7 +59,7 @@ - (void) dialogDidSucceed:(NSURL*)url {
}
}

if ((token == (NSString *) [NSNull null]) || (token.length ==0)) {
if ((token == (NSString *) [NSNull null]) || (token.length == 0)) {
[self dialogDidCancel:url];
[self dismissWithSuccess:NO animated:YES];
} else {
Expand All @@ -76,17 +76,17 @@ - (void) dialogDidSucceed:(NSURL*)url {
*/
- (void)dialogDidCancel:(NSURL *)url {
[self dismissWithSuccess:NO animated:YES];
if ([_loginDelegate respondsToSelector:@selector(fbDialogNotLogin)]) {
[_loginDelegate fbDialogNotLogin];
if ([_loginDelegate respondsToSelector:@selector(fbDialogNotLogin:)]) {
[_loginDelegate fbDialogNotLogin:YES];
}
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
if (!(([error.domain isEqualToString:@"NSURLErrorDomain"] && error.code == -999) ||
([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102))) {
[super webView:webView didFailLoadWithError:error];
if ([_loginDelegate respondsToSelector:@selector(fbDialogNotLogin)]) {
[_loginDelegate fbDialogNotLogin];
if ([_loginDelegate respondsToSelector:@selector(fbDialogNotLogin:)]) {
[_loginDelegate fbDialogNotLogin:NO];
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions src/FBRequest.h
Expand Up @@ -101,6 +101,12 @@
*/
- (void)request:(FBRequest*)request didLoad:(id)result;

/**
* Called when a request returns a response.
*
* The result object is the raw response from the server of type NSData
*/
- (void)request:(FBRequest*)request didLoadRawResponse:(NSData*)data;

@end

23 changes: 17 additions & 6 deletions src/FBRequest.m
Expand Up @@ -223,15 +223,26 @@ - (void)failWithError:(NSError*)error {
* private helper function: handle the response data
*/
- (void)handleResponseData:(NSData*)data {
NSError* error = nil;
id result = [self parseJsonResponse:data error:&error];
if (error) {
[self failWithError:error];
} else if ([_delegate respondsToSelector:@selector(request:didLoad:)]) {
[_delegate request:self didLoad:result];
if ([_delegate respondsToSelector:@selector(request:didLoadRawResponse:)]) {
[_delegate request:self didLoadRawResponse:data];
}

if ([_delegate respondsToSelector:@selector(request:didLoad:)] ||
[_delegate respondsToSelector:@selector(request:didFailWithError:)]) {
NSError* error = nil;
id result = [self parseJsonResponse:data error:&error];
if (error) {
[self failWithError:error];
} else if ([_delegate respondsToSelector:@selector(request:didLoad:)]) {
[_delegate request:self didLoad:(result == nil ? data : result)];
}

}

}



//////////////////////////////////////////////////////////////////////////////////////////////////
// public

Expand Down
2 changes: 1 addition & 1 deletion src/Facebook.h
Expand Up @@ -96,7 +96,7 @@
/**
* Called when the user dismiss the dialog without login
*/
- (void)fbDidNotLogin;
- (void)fbDidNotLogin:(BOOL)cancelled;

/**
* Called when the user is logged out
Expand Down
8 changes: 4 additions & 4 deletions src/Facebook.m
Expand Up @@ -411,9 +411,9 @@ - (void)fbDialogLogin:(NSString *)token expirationDate:(NSDate *)expirationDate
/**
* Did not login call the not login delegate
*/
- (void) fbDialogNotLogin {
if ([self.sessionDelegate respondsToSelector:@selector(fbDidNotLogin)]) {
[_sessionDelegate fbDidNotLogin];
- (void) fbDialogNotLogin:(BOOL)cancelled {
if ([self.sessionDelegate respondsToSelector:@selector(fbDidNotLogin:)]) {
[_sessionDelegate fbDidNotLogin:cancelled];
}
}

Expand All @@ -425,7 +425,7 @@ - (void) fbDialogNotLogin {
* Handle the auth.ExpireSession api call failure
*/
- (void)request:(FBRequest*)request didFailWithError:(NSError*)error{
NSLog(@"Failed to expiration the session");
NSLog(@"Failed to expire the session");
}

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 57818a0

Please sign in to comment.