Advertisement
Guest User

Untitled

a guest
Jun 19th, 2013
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. -(IBAction)loginfb:(id)sender
  2. {
  3. NSUserDefaults *userlogin=[NSUserDefaults standardUserDefaults];
  4. [userlogin removeObjectForKey:@"Safari"];
  5. if(NSClassFromString(@"SLComposeViewController") != nil)
  6. {
  7. ACAccountStore *account = [[ACAccountStore alloc] init];
  8. ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:
  9. ACAccountTypeIdentifierFacebook];
  10. NSDictionary *options = @{ACFacebookAppIdKey : @"457181451029974",
  11. ACFacebookPermissionsKey : @[@"email"],
  12. ACFacebookAudienceKey:ACFacebookAudienceEveryone};
  13. [account requestAccessToAccountsWithType:accountType options:options
  14. completion:^(BOOL granted, NSError *error)
  15. {
  16. if (granted == YES)
  17. {
  18. NSArray *arrayOfAccounts = [account
  19. accountsWithAccountType:accountType];
  20. if ([arrayOfAccounts count] > 0)
  21. {
  22. if (self.gotUserDetails)
  23. {
  24. return;
  25. }
  26. [self fetchuserinfo];
  27. NSUserDefaults *userlogin=[NSUserDefaults standardUserDefaults];
  28. [userlogin setObject:@"useradded" forKey:@"login"];
  29. }
  30. else
  31. {
  32. [self safariauth];
  33. }
  34. }
  35.  
  36.  
  37.  
  38. }];
  39. }
  40.  
  41. -(void)safariauth
  42. {
  43. AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
  44.  
  45. if (appDelegate.session.isOpen)
  46. {
  47.  
  48. [appDelegate.session closeAndClearTokenInformation];
  49. appDelegate.session = [[FBSession alloc] init];
  50.  
  51.  
  52. [appDelegate.session openWithCompletionHandler:^(FBSession *session,
  53. FBSessionState status,
  54. NSError *error) {
  55. // and here we make sure to update our UX according to the new session state
  56. [self updateView];
  57. }];
  58. }
  59. else
  60. {
  61.  
  62. if (appDelegate.session.state != FBSessionStateCreated)
  63. {
  64. appDelegate.session = [[FBSession alloc] init];
  65. }
  66.  
  67. [appDelegate.session openWithCompletionHandler:^(FBSession *session,
  68. FBSessionState status,
  69. NSError *error) {
  70. // and here we make sure to update our UX according to the new session state
  71. [self updateView];
  72. }];
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement