Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -(IBAction)loginfb:(id)sender
- {
- NSUserDefaults *userlogin=[NSUserDefaults standardUserDefaults];
- [userlogin removeObjectForKey:@"Safari"];
- if(NSClassFromString(@"SLComposeViewController") != nil)
- {
- ACAccountStore *account = [[ACAccountStore alloc] init];
- ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
- ACAccountTypeIdentifierFacebook];
- NSDictionary *options = @{ACFacebookAppIdKey : @"457181451029974",
- ACFacebookPermissionsKey : @[@"email"],
- ACFacebookAudienceKey:ACFacebookAudienceEveryone};
- [account requestAccessToAccountsWithType:accountType options:options
- completion:^(BOOL granted, NSError *error)
- {
- if (granted == YES)
- {
- NSArray *arrayOfAccounts = [account
- accountsWithAccountType:accountType];
- if ([arrayOfAccounts count] > 0)
- {
- if (self.gotUserDetails)
- {
- return;
- }
- [self fetchuserinfo];
- NSUserDefaults *userlogin=[NSUserDefaults standardUserDefaults];
- [userlogin setObject:@"useradded" forKey:@"login"];
- }
- else
- {
- [self safariauth];
- }
- }
- }];
- }
- -(void)safariauth
- {
- AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
- if (appDelegate.session.isOpen)
- {
- [appDelegate.session closeAndClearTokenInformation];
- appDelegate.session = [[FBSession alloc] init];
- [appDelegate.session openWithCompletionHandler:^(FBSession *session,
- FBSessionState status,
- NSError *error) {
- // and here we make sure to update our UX according to the new session state
- [self updateView];
- }];
- }
- else
- {
- if (appDelegate.session.state != FBSessionStateCreated)
- {
- appDelegate.session = [[FBSession alloc] init];
- }
- [appDelegate.session openWithCompletionHandler:^(FBSession *session,
- FBSessionState status,
- NSError *error) {
- // and here we make sure to update our UX according to the new session state
- [self updateView];
- }];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement