SFUserAccount始终为零

时间:2017-09-26 18:38:26

标签: ios objective-c iphone salesforce salesforce-ios-sdk

我已将salesforcesdk-ios更新为新版本5.3.0。成功登录后,我在此委托中设置了所有这些值 - oauthCoordinatorDidAuthenticate:authInfo:,就像这样,

- (void) oauthCoordinatorDidAuthenticate: (SFOAuthCoordinator *) coordinator authInfo:(SFOAuthInfo *)info {

    [SFAuthenticationManager sharedManager].coordinator = coordinator;
    [[SFAuthenticationManager sharedManager] coordinator].credentials = coordinator.credentials;
    [[SFUserAccountManager sharedInstance] applyCredentials:coordinator.credentials];
}

当我尝试验证refreshtoken时,currentUser在 - (void)中为nil发送:(SFRestRequest *)请求委托:(id)委托shouldRetry:(BOOL)shouldRetry 并始终加载salesforce登录页面而不是向Salesforce发送请求。

//如果没有可证明的身份验证凭据,请在发送前登录。 SFUserAccount * user = [SFUserAccountManager sharedInstance] .currentUser;

用户永远是零。如何正确设置useraccount?谢谢!

2 个答案:

答案 0 :(得分:0)

首先,我认为您可以检查代理 oauthCoordinatorDidAuthenticate:authInfo:是否有效。像:

- (void) oauthCoordinatorDidAuthenticate: (SFOAuthCoordinator *) coordinator authInfo:(SFOAuthInfo *)info {
print("delegate is worked")
[SFAuthenticationManager sharedManager].coordinator = coordinator;
[[SFAuthenticationManager sharedManager] coordinator].credentials = coordinator.credentials;
[[SFUserAccountManager sharedInstance] applyCredentials:coordinator.credentials];

}

当委托人没有工作时,可能导致用户为零。

答案 1 :(得分:0)

我找到了答案。他们期望在较新版本的iOS sdk中明确设置currentUser。我有一个自定义登录屏幕,切换到沙箱和生产之间切换。我现在正在这个方法中设置用户帐户 -

   [[SFAuthenticationManager sharedManager] loginWithCompletion:^(SFOAuthInfo *authInfo,SFUserAccount *userAccount) {
        [SFSDKCoreLogger i:[self class] format:@"Authentication (%@) succeeded.  Launch completed.", authInfo.authTypeDescription];
        [SFUserAccountManager sharedInstance].currentUser = userAccount;
        [SFSecurityLockout setupTimer];
        [SFSecurityLockout startActivityMonitoring];
        s_loggedIn = YES;
    } failure:^(SFOAuthInfo *authInfo, NSError *authError) {
        [SFSDKCoreLogger e:[self class] format:@"Authentication (%@) failed: %@.", (authInfo.authType == SFOAuthTypeUserAgent ? @"User Agent" : @"Refresh"), [authError localizedDescription]];
    }];