Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update sample app to show how to handle dialog request results

Summary:
Part of the discussion of the abandoned diff https://phabricator.fb.com/D342789
was that we should update the Hackbook iOS sample app to show developers how to
process data passed back from the dialog. Changes were made to use
dialogCompleteWithUrl: instead of
 dialogDidComplete: method. Other tweaks made to display a success message back
to the user when an app request was sent. Also NSLog the post_id and request_ids
information so developer can check these out.

Changes still need to be made to the iOS SDK docs
(https://developers.facebook.com/docs/reference/iossdk/FBDialogDelegate/) to let
developers know how to handle the dialog data in the callback.

Test Plan:
1/ On iOS simulator 4.3 ran through the Publish Feed and Send Request flows.
Checked it works and shows the proper user messages and debug messages (that
developers could use in the future).
2/ Tested on iPhone 5.0 and tested feed and app request dialog flows.

Reviewers: brent

Reviewed By: brent

CC: lshepard, yariv, brent, caabernathy

Differential Revision: 360490

Revert Plan: OK

Task ID: 697899
  • Loading branch information...
commit e9df55100541e58427a641f3033fa66b97a90c8a 1 parent 32423dc
Christine Abernathy authored Christine Abernathy committed
Showing with 51 additions and 3 deletions.
  1. +51 −3 sample/Hackbook/Hackbook/APICallsViewController.m
View
54 sample/Hackbook/Hackbook/APICallsViewController.m
@@ -290,6 +290,23 @@ - (void)apiButtonClicked:(id) sender
}
}
+/**
+ * Helper method to parse URL query parameters
+ */
+- (NSDictionary *) parseURLParams:(NSString *)query {
+ NSArray *pairs = [query componentsSeparatedByString:@"&"];
+ NSMutableDictionary *params = [[[NSMutableDictionary alloc] init] autorelease];
+ for (NSString *pair in pairs) {
+ NSArray *kv = [pair componentsSeparatedByString:@"="];
+ NSString *val =
+ [[kv objectAtIndex:1]
+ stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+
+ [params setObject:val forKey:[kv objectAtIndex:0]];
+ }
+ return params;
+}
+
#pragma mark - Facebook API Calls
/*
* Graph API: Method to get the user's friends.
@@ -1160,14 +1177,45 @@ - (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
#pragma mark - FBDialogDelegate Methods
/**
- * Called when a UIServer Dialog successfully return.
+ * Called when a UIServer Dialog successfully return. Using this callback
+ * instead of dialogDidComplete: to properly handle successful shares/sends
+ * that return ID data back.
*/
-- (void)dialogDidComplete:(FBDialog *)dialog {
+- (void)dialogCompleteWithUrl:(NSURL *)url {
+ if (![url query]) {
+ NSLog(@"User canceled dialog or there was an error");
+ return;
+ }
+
+ NSDictionary *params = [self parseURLParams:[url query]];
switch (currentAPICall) {
case kDialogFeedUser:
case kDialogFeedFriend:
{
- [self showMessage:@"Published feed successfully."];
+ // Successful posts return a post_id
+ if ([params valueForKey:@"post_id"]) {
+ [self showMessage:@"Published feed successfully."];
+ NSLog(@"Feed post ID: %@", [params valueForKey:@"post_id"]);
+ }
+ break;
+ }
+ case kDialogRequestsSendToMany:
+ case kDialogRequestsSendToSelect:
+ case kDialogRequestsSendToTarget:
+ {
+ // Successful requests return one or more request_ids.
+ // Get any request IDs, will be in the URL in the form
+ // request_ids[0]=1001316103543&request_ids[1]=10100303657380180
+ NSMutableArray *requestIDs = [[NSMutableArray alloc] init];
+ for (NSString *paramKey in params) {
+ if ([paramKey hasPrefix:@"request_ids"]) {
+ [requestIDs addObject:[params objectForKey:paramKey]];
+ }
+ }
+ if ([requestIDs count] > 0) {
+ [self showMessage:@"Sent request successfully."];
+ NSLog(@"Request ID(s): %@", requestIDs);
+ }
break;
}
default:
Please sign in to comment.
Something went wrong with that request. Please try again.