Skip to content

Commit

Permalink
theRunAround demo app make a few new object to handle different request
Browse files Browse the repository at this point in the history
  • Loading branch information
Yujuan Bao committed Aug 5, 2010
1 parent 9cbd90d commit 8732684
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 41 deletions.
2 changes: 0 additions & 2 deletions README.mdown
Expand Up @@ -11,8 +11,6 @@ Known Issues

* If you see "an invalid next or cancel parameter was specified" message in the login dialog, then you need to migrate your application to the New Data Permissions. This can be done by going to http://www.facebook.com/developers/apps.php then selecting the application you are testing with, and clicking "Edit Settings" (the third item underneath Total Users). On the settings page, click on Migrations (bottom of the left menu), then set New Data Permissions to "Enabled"

* The dialog webviews may be blank if an error occurs -- we are working on figuring these out and providing more debugging information. Sorry for the frustration.

Getting Started
===============

Expand Down
2 changes: 1 addition & 1 deletion sample/DemoApp/Classes/DemoAppViewController.m
Expand Up @@ -20,7 +20,7 @@

// Your Facebook APP Id must be set before running this example
// See http://www.facebook.com/developers/createapp.php
static NSString* kAppId = nil;
static NSString* kAppId = @"230820755197";

@implementation DemoAppViewController

Expand Down
13 changes: 12 additions & 1 deletion sample/DemoApp/DemoApp.xcodeproj/project.pbxproj
Expand Up @@ -269,26 +269,37 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CODE_SIGN_IDENTITY = 9CMR37QPRU;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
GCC_DYNAMIC_NO_PIC = NO;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = DemoApp_Prefix.pch;
INFOPLIST_FILE = "DemoApp-Info.plist";
PRODUCT_NAME = DemoApp;
SDKROOT = iphonesimulator4.0;
PROVISIONING_PROFILE = "";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphoneos4.0;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
};
1D6058950D05DD3E006BFB54 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CODE_SIGN_IDENTITY = 9CMR37QPRU;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = DemoApp_Prefix.pch;
INFOPLIST_FILE = "DemoApp-Info.plist";
PRODUCT_NAME = DemoApp;
PROVISIONING_PROFILE = "";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphoneos4.0;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
34 changes: 34 additions & 0 deletions sample/theRunAround/Classes/FriendsRequestResult.h
@@ -0,0 +1,34 @@
/*
* Copyright 2010 Facebook
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "FBConnect.h"

@protocol FriendsRequestDelegate;

@interface FriendsRequestResult : NSObject<FBRequestDelegate> {
id<FriendsRequestDelegate> _friendsRequestDelegate;
}

- (id) initializeWithDelegate: (id<FriendsRequestDelegate>)delegate;

@end

@protocol FriendsRequestDelegate<NSObject>

- (void)FriendsRequestCompleteWithFriendsInfo:(NSMutableArray *)friendsInfo;

@end
57 changes: 57 additions & 0 deletions sample/theRunAround/Classes/FriendsRequestResult.m
@@ -0,0 +1,57 @@
/*
* Copyright 2010 Facebook
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "FriendsRequestResult.h"


@implementation FriendsRequestResult

- (id) initializeWithDelegate:(id<FriendsRequestDelegate>)delegate {
self = [super init];
_friendsRequestDelegate = [delegate retain];
return self;
}

/**
* FBRequestDelegate
*/
- (void)request:(FBRequest*)request didLoad:(id)result{

NSMutableArray *friendsInfo = [[[[NSMutableArray alloc] init] autorelease] retain];
for (NSDictionary *info in result) {
NSString *friend_id = [NSString stringWithString:[[info objectForKey:@"uid"] stringValue]];
NSString *friend_name = nil;
if ([info objectForKey:@"name"] != [NSNull null]) {
friend_name = [NSString stringWithString:[info objectForKey:@"name"]];
}
NSString *friend_pic = [info objectForKey:@"pic_square"];
NSString *friend_status = [info objectForKey:@"status"];
NSMutableDictionary *friend_info = [NSMutableDictionary dictionaryWithObjectsAndKeys:
friend_id,@"uid",
friend_name, @"name",
friend_pic, @"pic",
friend_status, @"status",
nil];
[friendsInfo addObject:friend_info];
}


[_friendsRequestDelegate FriendsRequestCompleteWithFriendsInfo:friendsInfo];

}


@end
4 changes: 3 additions & 1 deletion sample/theRunAround/Classes/UserInfo.h
Expand Up @@ -16,10 +16,12 @@

#import <UIKit/UIKit.h>
#import "FBConnect.h"
#import "UserRequestResult.h"
#import "FriendsRequestResult.h"

@protocol UserInfoLoadDelegate;

@interface UserInfo : NSObject<FBRequestDelegate> {
@interface UserInfo : NSObject<UserRequestDelegate, FriendsRequestDelegate> {
NSString *_uid;
NSMutableArray * _friendsList;
NSMutableArray *_friendsInfo;
Expand Down
55 changes: 23 additions & 32 deletions sample/theRunAround/Classes/UserInfo.m
Expand Up @@ -18,6 +18,7 @@
#import "FBConnect.h"



@implementation UserInfo

@synthesize facebook = _facebook,
Expand Down Expand Up @@ -62,7 +63,9 @@ - (void) requestAllInfo {
* an intermediate solution to get the logged in user id.
*/
- (void) requestUid{
[_facebook requestWithGraphPath:@"me" andDelegate:self];
UserRequestResult *userRequestResult =
[[[[UserRequestResult alloc] initializeWithDelegate:self] autorelease] retain];
[_facebook requestWithGraphPath:@"me" andDelegate:userRequestResult];
}

/**
Expand All @@ -71,6 +74,9 @@ - (void) requestUid{
* Use FQL to query detailed friends information
*/
- (void) requestFriendsDetail{
FriendsRequestResult *friendsRequestResult =
[[[[FriendsRequestResult alloc] initializeWithDelegate:self] autorelease] retain];

NSString *query = @"SELECT uid, name, pic_square, status FROM user WHERE uid IN (";
query = [query stringByAppendingFormat:@"SELECT uid2 FROM friend WHERE uid1 = %@)", _uid];
NSMutableDictionary * params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
Expand All @@ -79,47 +85,32 @@ - (void) requestFriendsDetail{
[_facebook requestWithMethodName: @"fql.query"
andParams: params
andHttpMethod: @"POST"
andDelegate: self];
andDelegate: friendsRequestResult];
[query release];
}

/**
* FBRequestDelegate
* UserRequestDelegate
*/
- (void)request:(FBRequest*)request didLoad:(id)result{

if ([request.url hasPrefix:@"https://graph.facebook.com/me"]) {
self.uid = [result objectForKey:@"id"];
[self requestFriendsDetail];
} else {
_friendsInfo = [[[[NSMutableArray alloc] init] autorelease] retain];
for (NSDictionary *info in result) {
NSString *friend_id = [NSString stringWithString:[[info objectForKey:@"uid"] stringValue]];
NSString *friend_name = nil;
if ([info objectForKey:@"name"] != [NSNull null]) {
friend_name = [NSString stringWithString:[info objectForKey:@"name"]];
}
NSString *friend_pic = [info objectForKey:@"pic_square"];
NSString *friend_status = [info objectForKey:@"status"];
NSMutableDictionary *friend_info = [NSMutableDictionary dictionaryWithObjectsAndKeys:
friend_id,@"uid",
friend_name, @"name",
friend_pic, @"pic",
friend_status, @"status",
nil];
[_friendsInfo addObject:friend_info];
}
if ([self.userInfoDelegate respondsToSelector:@selector(userInfoDidLoad)]) {
[_userInfoDelegate userInfoDidLoad];
}
}
- (void)userRequestCompleteWithUid:(NSString *)uid {
self.uid = uid;
[self requestFriendsDetail];
}

- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
NSLog(@"%@",[error localizedDescription]);
- (void)userRequestFailed {
if ([self.userInfoDelegate respondsToSelector:@selector(userInfoFailToLoad)]) {
[_userInfoDelegate userInfoFailToLoad];
}
}

/**
* FriendsRequestDelegate
*/
- (void)FriendsRequestCompleteWithFriendsInfo:(NSMutableArray *)friendsInfo {
_friendsInfo = [friendsInfo retain];
if ([self.userInfoDelegate respondsToSelector:@selector(userInfoDidLoad)]) {
[_userInfoDelegate userInfoDidLoad];
}
}

@end
36 changes: 36 additions & 0 deletions sample/theRunAround/Classes/UserRequestResult.h
@@ -0,0 +1,36 @@
/*
* Copyright 2010 Facebook
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import <Foundation/Foundation.h>
#import "FBConnect.h"

@protocol UserRequestDelegate;

@interface UserRequestResult : NSObject<FBRequestDelegate> {
id<UserRequestDelegate> _userRequestDelegate;
}

- (id) initializeWithDelegate: (id<UserRequestDelegate>)delegate;

@end

@protocol UserRequestDelegate<NSObject>

- (void)userRequestCompleteWithUid:(NSString *)uid;

- (void)userRequestFailed;

@end
45 changes: 45 additions & 0 deletions sample/theRunAround/Classes/UserRequestResult.m
@@ -0,0 +1,45 @@
/*
* Copyright 2010 Facebook
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#import "UserRequestResult.h"


@implementation UserRequestResult

- (id) initializeWithDelegate:(id<UserRequestDelegate>)delegate {
self = [super init];
_userRequestDelegate = [delegate retain];
return self;
}


/**
* FBRequestDelegate
*/
- (void)request:(FBRequest*)request didLoad:(id)result{

NSString *uid = [result objectForKey:@"id"];
[_userRequestDelegate userRequestCompleteWithUid:uid];

}


- (void)request:(FBRequest*)request didFailWithError:(NSError*)error {
NSLog(@"%@",[error localizedDescription]);
[_userRequestDelegate userRequestFailed];
}

@end
2 changes: 1 addition & 1 deletion sample/theRunAround/Classes/mainViewController.m
Expand Up @@ -23,7 +23,7 @@

// Your Facebook App Id must be set before running this example
// See http://www.facebook.com/developers/createapp.php
static NSString* kAppId = nil;
static NSString* kAppId = @"230820755197";

@implementation mainViewController

Expand Down

0 comments on commit 8732684

Please sign in to comment.