我的要求是在某些条件下通过代码关闭 Facebook 窗口。我正在使用Facebook iOS SDK 3.5.1。
有什么方法可以在运行的应用程序上显示(Facebook)屏幕或以编程方式关闭 Facebook 屏幕?
我在 2 种情况下使用 facebook-
- 用于登录
- 用于发送应用请求。
两者的代码如下 -
1.登录:
AppDelegate *appDelegate = (AppDelegate*)[UIApplication sharedApplication].delegate;
if (appDelegate.session.state != FBSessionStateCreated || !appDelegate.session.isOpen) {
// Create a new, logged out session.
NSArray *permissions = [NSArray arrayWithObjects:@"publish_stream",@"user_birthday",@"user_photos", @"email", @"user_location", @"user_hometown", nil];
appDelegate.session = [[FBSession alloc] initWithPermissions:permissions];
}
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
if (appDelegate.session.state!=258 && appDelegate.session.state!=257) {
[self accessTokenFound:appDelegate.session.accessToken];
}
}];
2.对于应用请求
NSMutableDictionary* params = [NSMutableDictionary dictionary];
AppDelegate* appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[params setObject:friendID forKey:@"to"];
// Display the requests dialog
[FBWebDialogs
presentRequestsDialogModallyWithSession:appDelegate.session
message:message
title:nil
parameters:params
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
if (error) {
NSLog(@"Error sending request.");
} else {
if (result == FBWebDialogResultDialogNotCompleted) {
NSLog(@"User canceled request.");
} else {
NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
if (![urlParams valueForKey:@"request"]) {
NSLog(@"User canceled request.");
} else {
NSString *requestID = [urlParams valueForKey:@"request"];
[self requestSentSuccessfully];
}
}
}
}];