Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. @interface SalesforceManager : NSObject <SFAuthenticationManagerDelegate, SFUserAccountManagerDelegate, SFRestDelegate>
  2.  
  3. - (id)init
  4. {
  5. self = [super init];
  6.  
  7. if(self)
  8. {
  9. [SFLogger setLogLevel:SFLogLevelDebug];
  10.  
  11. // These SFAccountManager settings are the minimum required to identify the Connected App.
  12. [SFUserAccountManager sharedInstance].oauthClientId = RemoteAccessConsumerKey;
  13. [SFUserAccountManager sharedInstance].oauthCompletionUrl = OAuthRedirectURI;
  14. [SFUserAccountManager sharedInstance].scopes = [NSSet setWithObjects:@"web", @"api", nil];
  15.  
  16. // Auth manager delegate, for receiving logout and login host change events.
  17. [[SFAuthenticationManager sharedManager] addDelegate:self];
  18. [[SFUserAccountManager sharedInstance] addDelegate:self];
  19. }
  20.  
  21. return self;
  22. }
  23.  
  24. - (void)attemptLoginOnSuccess:(SFManagerLoginSuccessBlock)successBlock
  25. onFailure:(SFManagerLoginFailBlock)failureBlock
  26. {
  27. __weak SalesforceManager *weakSelf = self;
  28.  
  29. self.initialLoginSuccessBlock = ^(SFOAuthInfo *info)
  30. {
  31. weakSelf.authenticated = TRUE;
  32. successBlock();
  33.  
  34. };
  35.  
  36. self.initialLoginFailureBlock = ^(SFOAuthInfo *info, NSError *error)
  37. {
  38. [[SFAuthenticationManager sharedManager] logout];
  39. weakSelf.authenticated = FALSE;
  40. failureBlock();
  41. };
  42.  
  43. [[SFAuthenticationManager sharedManager] loginWithCompletion:self.initialLoginSuccessBlock failure:self.initialLoginFailureBlock];
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement