我们的 Worklight 项目中有一个“iPhone”环境,用于在 XCode 5 中进行本机 iOS 客户端开发。尽管在 Worklight 控制台中禁用了应用程序身份验证,但我们遇到了身份验证错误。
我们遵循的步骤是:
- 调用
wlConnectWithDelegate:
方法开启WLClient sharedInstance
- 成功后
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-Authentication-Failure/“非法状态”响应是否有其他来源?
我们在这里用我们的连接和调用错误地实现了一些东西吗?有没有一种解决方案可以让我们在应用启动后调用的第一个适配器不会失败?