如何将zksforce与本机ios集成并创建自定义登录以获取sales force用户字段

如何将zksforce与本机ios集成并创建自定义登录以获取sales force用户字段,ios,xcode,salesforce,Ios,Xcode,Salesforce,我尝试使用用户名和密码+安全令牌自定义登录。但它返回错误或异常,如 Terminating app due to uncaught exception 'INVALID_LOGIN', reason: 'INVALID_LOGIN: Invalid username, password, security token; or user locked out.' *** First throw call stack: ( 0 CoreFoundation

我尝试使用用户名和密码+安全令牌自定义登录。但它返回错误或异常,如

Terminating app due to uncaught exception 'INVALID_LOGIN', reason: 'INVALID_LOGIN: Invalid username, password, security token; or user locked out.'
*** First throw call stack:
(
    0   CoreFoundation                      0x018fb5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x0167e8b6 objc_exception_throw + 44
    2   lead miner sales force              0x0001932a -[ZKBaseClient sendRequest:name:returnRoot:] + 2266
    3   lead miner sales force              0x0001882a -[ZKBaseClient sendRequest:name:] + 90
    4   lead miner sales force              0x00004516 -[ZKSoapLogin login] + 358
    5   lead miner sales force              0x000107c1 -[ZKSforceClient soapLogin:] + 65
    6   lead miner sales force              0x00010965 -[ZKSforceClient login:password:] + 277
    7   lead miner sales force              0x0000b0fb -[loginViewController loginbutton:] + 315
    8   libobjc.A.dylib                     0x01690874 -[NSObject performSelector:withObject:withObject:] + 77
    9   UIKit                               0x003ee0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
    10  UIKit                               0x003ee04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
    11  UIKit                               0x004e60c1 -[UIControl sendAction:to:forEvent:] + 66
    12  UIKit                               0x004e6484 -[UIControl _sendActionsForEvents:withEvent:] + 577
    13  UIKit                               0x004e5733 -[UIControl touchesEnded:withEvent:] + 641
    14  UIKit                               0x0042b51d -[UIWindow _sendTouchesForEvent:] + 852
    15  UIKit                               0x0042c184 -[UIWindow sendEvent:] + 1232
    16  UIKit                               0x003ffe86 -[UIApplication sendEvent:] + 242
    17  UIKit                               0x003ea18f _UIApplicationHandleEventQueue + 11421
    18  CoreFoundation                      0x0188483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    19  CoreFoundation                      0x018841cb __CFRunLoopDoSources0 + 235
    20  CoreFoundation                      0x018a129e __CFRunLoopRun + 910
    21  CoreFoundation                      0x018a0ac3 CFRunLoopRunSpecific + 467
    22  CoreFoundation                      0x018a08db CFRunLoopRunInMode + 123
    23  GraphicsServices                    0x038a09e2 GSEventRunModal + 192
    24  GraphicsServices                    0x038a0809 GSEventRun + 104
    25  UIKit                               0x003ecd3b UIApplicationMain + 1225
    26  lead miner sales force              0x0001bd42 main + 130
    27  libdyld.dylib                       0x020a370d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type ZKSoapException
谢谢你的好意

-(IBAction)loginbutton:(id)sender
{

NSString *username=[NSString stringWithFormat:@"%@",usernamefield.text];
NSString *password=[NSString stringWithFormat:@"%@",passwordfield.text];

ZKSforceClient *sforce = [[ZKSforceClient alloc] init];
[sforce login:username password:password];

ZKDescribeSObject *taskDescribe = [sforce describeSObject:@"Task"];
NSLog(@"url for the new Task page is %@", [taskDescribe urlNew]);
[sforce release];
}

在ZKSforce中,
login:
调用(以及转到服务器的所有其他调用)将在服务器返回soap错误时抛出一个错误,如果您的凭据无效(这是您在所显示的堆栈跟踪中报告的情况),它就会这样做。您需要使用Objective-C的异常处理来捕获此异常并对其进行处理,例如

@try {
    [sforce login:username password:password];
    ZKDescribeSObject *task = [sforce describeSObject:@"Task"];

} @catch (ZKSoapException *ex) {
   NSLog(@"login failed %@", [ex reason]);
   // show to user etc, whatever you want to do when login fails.
}

您需要在编译时为您的项目启用objective-c异常,我认为这是一段时间以来的默认设置。

在swift中,您可以使用此选项

let username = "abc@gmail.com"
let password = "1234" + "yourtoken"
let client = ZKSforceClient()
client.performLogin(username, password: password, fail:{ (fail) in
            print(fail)

        }) { (success) in
            print(success)

        }

它将给你正确的异常处理失败和成功。希望它会工作

感谢您的友好重播,但我也尝试了您的答案,但它也向我显示了无效的_登录:无效的用户名、密码、安全令牌;或用户被锁定。但是我为登录提供了正确的沙盒测试域,但是我无法登录。感谢advance..如果您想登录到sandbox,您需要在调用loginHey@vikram之前调用setLoginHostAndProtocol:method passing,我使用的代码与您提供的代码相同,但我遇到了以下错误-:使用未解析标识符“zksforceCLient”。在swiftCan中,请提供控制台日志,并验证ZKSforce客户端sdk。您需要导入ZKSforce。无论您在何处使用上述代码。