Skip to content

Commit

Permalink
Add app_id to dialog requests.
Browse files Browse the repository at this point in the history
Updated the dialog() method to always include app_id. This will prevent
an error if a dialog is requested and the application doesn't have an
access token. App_id must now be specified in the Facebook constructor
as this saves specifying it with every request. Xcode project has been
updated to build with iOS SDK 4.3.
  • Loading branch information
Jim Brusstar committed Dec 8, 2010
1 parent 6e15463 commit c0ee436
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
7 changes: 3 additions & 4 deletions sample/DemoApp/Classes/DemoAppViewController.m
Expand Up @@ -54,7 +54,7 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
* Set initial view
*/
- (void)viewDidLoad {
_facebook = [[Facebook alloc] init];
_facebook = [[Facebook alloc] initWithAppId:kAppId];
[self.label setText:@"Please log in"];
_getUserInfoButton.hidden = YES;
_getPublicInfoButton.hidden = YES;
Expand Down Expand Up @@ -86,7 +86,7 @@ - (void)dealloc {
* Show the authorization dialog.
*/
- (void)login {
[_facebook authorize:kAppId permissions:_permissions delegate:self];
[_facebook authorize:_permissions delegate:self];
}

/**
Expand Down Expand Up @@ -150,14 +150,13 @@ - (IBAction)publishStream:(id)sender {
@"http://itsti.me/", @"href", nil];
NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"api_key",
@"Share on Facebook", @"user_message_prompt",
actionLinksStr, @"action_links",
attachmentStr, @"attachment",
nil];


[_facebook dialog:@"stream.publish"
[_facebook dialog:@"feed"
andParams:params
andDelegate:self];

Expand Down
17 changes: 11 additions & 6 deletions sample/DemoApp/DemoApp.xcodeproj/project.pbxproj
Expand Up @@ -287,7 +287,7 @@
PRODUCT_NAME = DemoApp;
PROVISIONING_PROFILE = "";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphonesimulator4.1;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
};
name = Debug;
Expand All @@ -305,7 +305,7 @@
PRODUCT_NAME = DemoApp;
PROVISIONING_PROFILE = "";
"PROVISIONING_PROFILE[sdk=iphoneos*]" = "";
SDKROOT = iphonesimulator4.0;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = 1;
VALIDATE_PRODUCT = YES;
};
Expand All @@ -316,14 +316,15 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Don't Code Sign";
ENABLE_OPENMP_SUPPORT = YES;
ENABLE_OPENMP_SUPPORT = NO;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
ONLY_ACTIVE_ARCH = NO;
PREBINDING = NO;
SDKROOT = iphonesimulator4.1;
VALID_ARCHS = "armv8 armv7 i386";
SDKROOT = iphoneos;
VALID_ARCHS = "armv7 armv6";
};
name = Debug;
};
Expand All @@ -332,12 +333,16 @@
buildSettings = {
ARCHS = "$(ARCHS_STANDARD_32_BIT)";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
ENABLE_OPENMP_SUPPORT = NO;
GCC_C_LANGUAGE_STANDARD = c99;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 3.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
PREBINDING = NO;
SDKROOT = iphonesimulator4.1;
SDKROOT = iphoneos;
VALID_ARCHS = "armv7 armv6";
};
name = Release;
};
Expand Down
4 changes: 2 additions & 2 deletions src/Facebook.h
Expand Up @@ -42,9 +42,9 @@

@property(nonatomic, assign) id<FBSessionDelegate> sessionDelegate;

- (id)initWithAppId:(NSString *)app_id;

- (void)authorize:(NSString *)application_id
permissions:(NSArray *)permissions
- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate;

- (BOOL)handleOpenURL:(NSURL *)url;
Expand Down
20 changes: 15 additions & 5 deletions src/Facebook.m
Expand Up @@ -40,7 +40,19 @@ @implementation Facebook
///////////////////////////////////////////////////////////////////////////////////////////////////
// private

///////////////////////////////////////////////////////////////////////////////////////////////////

/**
* Initialize the Facebook object with application ID.
*/
- (id)initWithAppId:(NSString *)app_id {
self = [super init];
if (self) {
[_appId release];
_appId = [app_id copy];
}
return self;
}

/**
* Override NSObject : free the space
*/
Expand Down Expand Up @@ -196,11 +208,8 @@ - (NSDictionary*)parseURLParams:(NSString *)query {
* Callback interface for notifying the calling application when
* the user has logged in.
*/
- (void)authorize:(NSString *)application_id
permissions:(NSArray *)permissions
- (void)authorize:(NSArray *)permissions
delegate:(id<FBSessionDelegate>)delegate {
[_appId release];
_appId = [application_id copy];

[_permissions release];
_permissions = [permissions retain];
Expand Down Expand Up @@ -518,6 +527,7 @@ - (void)dialog:(NSString *)action
[params setObject:@"user_agent" forKey:@"type"];
_fbDialog = [[FBLoginDialog alloc] initWithURL:dialogURL loginParams:params delegate:self];
} else {
[params setObject:_appId forKey:@"app_id"];
if ([self isSessionValid]) {
[params setValue:[self.accessToken stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
forKey:@"access_token"];
Expand Down

0 comments on commit c0ee436

Please sign in to comment.