Reputation: 195
I've been trying to develop iOS app using Facebook and I'm new. So I've been trying to make
a login with Facebook, followed a tutorial on Facebook and try to implement it.
But I've encountered, [FBSession sessionOpenWithPermissions]
not found. When I run the
app, it will force close and say that error. When build the project, it will show warning
yellow exclamation that sessionOpenWithPermission
is not found in FBSession
The tutorial outdated? If it is, then what is the new code for the new Facebook SDK for
sessionOpenWithPermission ?
Upvotes: 15
Views: 2905
Reputation: 344
Maybe this code helps you, put it in your AppDelegate.m
class
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen: {
self.loggedinVCController = [[LoggedinVC alloc] initWithNibName:@"LoggedinVC" bundle:nil];
self.navController = [[UINavigationController alloc]initWithRootViewController:self.loggedinVCController];
self.window.rootViewControlle`enter code here`r = self.navController;
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
// Once the user has logged in, we want them to
// be looking at the root view.
[self.navController popToRootViewControllerAnimated:NO];
[FBSession.activeSession closeAndClearTokenInformation];
self.viewController = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
self.window.rootViewController = self.viewController;
break;
default:
break;
}
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
return [FBSession.activeSession handleOpenURL:url];
}
- (void)openSession
{
[FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:YES
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
Upvotes: 2
Reputation: 9246
Try This Code
account = [[ACAccountStore alloc] init];
accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
arrayOfAccounts = [account accountsWithAccountType:accountType];
appDelegate= (AppDelegate *)[[UIApplication sharedApplication] delegate];
chk=appDelegate.chk_login;
if (!appDelegate.session.isOpen) {
// create a fresh session object
appDelegate.session = [[FBSession alloc] init];
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
// even though we had a cached token, we need to login to make the session usable
[appDelegate.session openWithCompletionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// we recurse here, in order to update buttons and labels
}];
}
}
Upvotes: 2
Reputation: 987
Some code of line is missing in App Delegate.Just check that one.after that u will check open session and closed session on the time of calling method for Facebook.
Upvotes: 0
Reputation: 398
It opens the facebook seesion and optionally shows the login ux
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
@"user_likes",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];}
Upvotes: 1
Reputation: 1258
you can also use Sharekit It is very easy to implement and also supports other social networks. sharekit
Upvotes: 0
Reputation: 1622
Possible duplicate of Facebook iOS SDK 3.0 Login Tutorial Issue with FBSession
//REPLACE
[FBSession sessionOpenWithPermissions:nil
completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
//WITH
[FBSession openActiveSessionWithPermissions:nil
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
Upvotes: 1
Reputation: 3294
Just copying @Stas Zhukovskiy answer in comments to the answer box:
there is a mismatch in the docs tutorial and the sample. You should use - (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI; instead. – Stas Zhukovskiy
Upvotes: 0