更新:看起来返回的图形对象没有更新。我已经更改了消息字段并验证了发件人正在发送正确的消息(至少它显示在 Web 对话框视图中),但接收者仍在接收旧消息。
我在读取附加到通过深度链接返回应用程序的 Facebook 请求的数据时遇到问题。我已经按照 facebook SDK 中的教程进行操作,并且可以发送/接收带有标题和消息的通知请求,但是我附加的数据似乎没有显示给接收者。这是我的代码:
发件人:
FBSBJSON *jsonWriter = [FBSBJSON new];
NSDictionary *gift = [NSDictionary dictionaryWithObjectsAndKeys:
@"5", @"social_karma",
@"1", @"badge_of_awesomeness",
nil];
NSString *giftStr = [jsonWriter stringWithObject:gift];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
giftStr, @"data",
nil];
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSArray *permissions = [NSArray arrayWithObjects:@"email", @"user_birthday", @"user_photos", nil];
appDelegate.session = [[FBSession alloc] initWithPermissions:permissions];
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
NSString *message = [NSString stringWithFormat:@"photoID:%@", self.photoModel.photoID];
// Display the requests dialog
[FBWebDialogs
presentRequestsDialogModallyWithSession:appDelegate.session
message:@"Learn how to make your iOS apps social."
title:@"What do you think? I just rate this person an "
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
// Error launching the dialog or sending the request.
NSLog(@"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
// User clicked the "x" icon
NSLog(@"User canceled request.");
} else {
// Handle the send request callback
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"request"]) {
// User clicked the Cancel button
NSLog(@"User canceled request.");
} else {
// User clicked the Send button
NSString *requestID = [urlParams valueForKey:@"request"];
NSLog(@"Request ID: %@", requestID);
}
}
}
}];
}];
接收方(在应用委托中):
- (void) notificationGet:(NSString *)requestid {
NSArray *permissions = [NSArray arrayWithObjects:@"email", @"user_birthday", @"user_photos", nil];
self.session = [[FBSession alloc] initWithPermissions:permissions];
[self.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
[FBSession setActiveSession:self.session];
[FBRequestConnection startWithGraphPath:requestid
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
NSString *title;
NSString *message;
if ([result objectForKey:@"data"]) {
title = [NSString
stringWithFormat:@"%@ sent you a gift",
[[result objectForKey:@"from"]
objectForKey:@"name"]];
FBSBJSON *jsonParser = [FBSBJSON new];
NSDictionary *requestData =
[jsonParser
objectWithString:[result objectForKey:@"data"]];
message =
[NSString stringWithFormat:@"Badge: %@, Karma: %@",
[requestData objectForKey:@"badge_of_awesomeness"],
[requestData objectForKey:@"social_karma"]];
} else {
title = [NSString
stringWithFormat:@"%@ sent you a request",
[[result objectForKey:@"from"] objectForKey:@"name"]];
message = [NSString stringWithString:
[result objectForKey:@"message"]];
}
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil,
nil];
[alert show];
}
}];
}];
}
同样,我能够通过,而不是数据(参数)来获取消息和标题。
谢谢!