Skip to content

Commit

Permalink
Fix the app ID decoding to handle the url suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenmemory committed Jun 4, 2012
1 parent 0022e99 commit 85c2303
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 23 deletions.
34 changes: 17 additions & 17 deletions src/FBFrictionlessRequestSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,21 @@ - (void)enableWithFacebook:(Facebook*)facebook {

- (void)reloadRecipientCacheWithFacebook:(Facebook *)facebook {
// request the list of frictionless recipients from the server
[facebook requestWithGraphPath:@"me/apprequestformerrecipients"
finalize:^(FBRequest *request) {
[request addCompletionHandler:^(FBRequest *request, id result) {
int items = [[result objectForKey: @"data"] count];
NSMutableArray* recipients = [[NSMutableArray alloc] initWithCapacity: items];
for (int i = 0; i < items; i++) {
[recipients addObject: [[[result objectForKey: @"data"]
objectAtIndex: i]
objectForKey: @"recipient_id"]] ;
}
self.allowedRecipients = recipients;
}];
}];
[facebook requestWithGraphPath:@"me/apprequestformerrecipients"
finalize:^(FBRequest *request) {
[request addCompletionHandler:^(FBRequest *request, id result) {
int items = [[result objectForKey: @"data"] count];
NSMutableArray* recipients = [[NSMutableArray alloc] initWithCapacity: items];
for (int i = 0; i < items; i++) {
[recipients addObject: [[[result objectForKey: @"data"]
objectAtIndex: i]
objectForKey: @"recipient_id"]] ;
}
self.allowedRecipients = recipients;
}];
}];
}

- (void)updateRecipientCacheWithRecipients:(NSArray*)ids {
Expand All @@ -80,8 +80,8 @@ - (void)updateRecipientCacheWithRecipients:(NSArray*)ids {
- (BOOL)isFrictionlessEnabledForRecipient:(NSString *)fbid {
// trim whitespace from edges
fbid = [fbid stringByTrimmingCharactersInSet:
[NSCharacterSet whitespaceCharacterSet]];

[NSCharacterSet whitespaceCharacterSet]];
// linear search through cache for a match
for (NSString *entry in self.allowedRecipients) {
if ([entry isEqualToString:fbid]) {
Expand Down
20 changes: 14 additions & 6 deletions src/Facebook.m
Original file line number Diff line number Diff line change
Expand Up @@ -254,23 +254,31 @@ - (void)_applyLoginDialogHandlers:(FBLoginDialog*)dialog {
* and redirect the user to Safari.
* @param delegate the FBSessionDelegate
*/
- (id)initWithAppID:(NSString *)_appId {
- (id)initWithAppID:(NSString *)_potentialAppID {
self = [super init];
if (self) {
_requests = [NSMutableSet set];
_lastAccessTokenUpdate = [NSDate distantPast];
_frictionlessRequestSettings = [[FBFrictionlessRequestSettings alloc] init];

NSCharacterSet *characterSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
NSRange range = [_appId rangeOfCharacterFromSet:characterSet];
NSRange range = NSMakeRange(0, 0);

self.appId = [_appId substringWithRange:range];
for( range.length = 0; range.length < [_potentialAppID length]; range.length++ ) {
if( ![characterSet characterIsMember:[_potentialAppID characterAtIndex:range.length]] ) {
break;
}
}

self.appId = [_potentialAppID substringWithRange:range];
self.urlSchemeSuffix = nil;

if( (range.location + range.length) < [_appId length] ) {
self.urlSchemeSuffix = [_appId substringFromIndex:(range.location + range.length)];
}

self.urlSchemeSuffix = [_potentialAppID substringFromIndex:(range.location + range.length)];
}

NSLog(@"Application ID: '%@', URL suffix: '%@'", self.appId, self.urlSchemeSuffix);

self.extendTokenOnApplicationActive = YES;

self.requestStarted = ^(FBRequest*_){};
Expand Down

0 comments on commit 85c2303

Please sign in to comment.