WL 6.0.0.1 iOS本机API身份验证失败



我们的Worklight项目中有一个"iPhone"环境,用于XCode 5中的本机iOS客户端开发。尽管Worklight控制台中禁用了应用程序身份验证,但我们还是收到了身份验证错误。

我们遵循的步骤是:

  1. WLClient sharedInstance上调用wlConnectWithDelegate:方法
  2. wlConnectWithDelegate成功后,我们用invokeProcedure:withDelegate:调用适配器过程

代码如下:

#import <BlocksKit/A2DynamicDelegate.h>
+ (void) connectToWorklightOnSuccess: (SuccessBlock) success onFailure: (FailureBlock) failure {
    WLClient *client = [WLClient sharedInstance];
    A2DynamicDelegate *dd = [client dynamicDelegateForProtocol: @protocol(WLDelegate) ];
    [dd implementMethod: @selector(onSuccess:) withBlock: success];
    [dd implementMethod: @selector(onFailure:) withBlock: failure];
    [client wlConnectWithDelegate:(id <WLDelegate>)dd];
}
+ (void) invokeProcedure: (WLProcedureInvocationData *) proc onSuccess: (SuccessBlock) success onFailure: (FailureBlock) failure {
    [WJServiceGateway connectToWorklightOnSuccess:^(WLResponse *response) {
        NSLog(@"WLClient connect succeeded");
        WLClient *client = [WLClient sharedInstance];
        A2DynamicDelegate *dd = [client dynamicDelegateForProtocol: @protocol(WLDelegate) ];
        [dd implementMethod: @selector(onSuccess:) withBlock: success];
        [dd implementMethod: @selector(onFailure:) withBlock: failure];
        [client invokeProcedure:proc withDelegate:(id<WLDelegate>) dd];
    } onFailure:^(WLFailResponse *failResponse) {
        NSLog(@"WLClient connect failed: %@", failResponse);
        [failure invoke];
    }];
}

第一次我们使用invokeProcedure:onSuccess:onFailure:方法时,我们得到错误响应:

Status: 403
InvocationResult: (null)
InvocationContext: (null)
Response text: /*-secure-
{"WL-Authentication-Failure":{"wl_antiXSRFRealm":{"reason":"illegal state"}}}*/
Error code: 0
Error message: (null)

在应用程序被终止并重新启动之前,后续调用成功且无错误。

这个问题可能与这些问题有关(事实上,这是发生在同一项目中的问题):

  • IBM Worklight-如何在本机iOS应用程序中启用应用程序真实性
  • https://stackoverflow.com/questions/18879189/wl-5-0-6-1-js-vs-ios-native-handlechallenge-queued-in-waitlist-and-only-cal

然而,奇怪的是,我们禁用了应用程序身份验证(Worklight控制台中的下拉选项),并且仍然看到身份验证错误。此WL身份验证失败/"非法状态"响应是否有其他来源?

我们在这里的连接和调用是否实现错误?有没有一种解决方案可以让我们在应用程序启动后的第一个适配器调用不会失败?

如评论中所述,这与应用程序真实性保护无关。

  • 您需要首先调用到Worklight Server的连接,并在其成功回调中调用适配器过程

  • 您也只能在应用程序启动时连接到Worklight Server,稍后在需要执行适配器过程调用时连接到。

有关本地iOS应用程序中连接和调用的工作示例,请参阅以下教程和示例:https://developer.ibm.com/mobilefirstplatform/documentation/getting-started-6-3/server-side-development/invoking-adapter-procedures-native-ios-applications/

最新更新