ibm mobilefirst - worklight 6.0 adapter native ios to hybrids application -
i can able call worklight 6.0 adapter invoke in ios native code (using objective-c) can not read adapter json response using cordova plugin hybrids application.
// invoke adapter
myconnectlistener *connectlistener = [[myconnectlistener alloc] initwithcontroller:self]; [[wlclient sharedinstance] wlconnectwithdelegate:connectlistener]; // calling adapter using objective-c wlprocedureinvocationdata *myinvocationdata = [[wlprocedureinvocationdata alloc] initwithadaptername:@"http_ws_adptr" procedurename:@"getbalance"]; myinvokelistener *invokelistener = [[myinvokelistener alloc] initwithcontroller: self]; [[wlclient sharedinstance] invokeprocedure:myinvocationdata withdelegate:invokelistener]; cdvpluginresult *pluginresult = [cdvpluginresult resultwithstatus:cdvcommandstatus_ok messageasstring:responsestring]; [self.commanddelegate sendpluginresult:pluginresult callbackid:command.callbackid];
// hybrids application call native code
cordova.exec(sayhellosuccess, sayhellofailure, "helloworldplugin", "sayhello", [name]);
above cordova.exec success , failed method not return value.
but can not able parse value cdvpluginresult method. please advice me. how can read adapter ios native hybrids application.
several things note:
you using worklight 6.0.0.x. in worklight 6.0.0.x there no proper session sharing between web , native views. meaning, if example call
wl.client.connect()
method in web view , connect() , adapter invocation in native view - these calls not share same session can lead race condition errors, inability share state between views , other unexpected events. not recommended.if approach you're looking implement in hybrid application therefore highly recommended upgrade either mobilefirst (previous known "worklight") v6.3 or v7.0 session sharing between web , native views available out-of-the-box.
although might want opt call adapter js code...
to work as-is in supplied project, can change implementation based on below.
note implementation below based on mfp 7.0, such adapter invocation code not work in 6.0.0.0x codebase. need alter based on own code in v6.0.0.x:
sayhello.h
#import <foundation/foundation.h> #import <cordova/cdv.h> #import "wlclient.h" #import "wldelegate.h" @interface sayhelloplugin : cdvplugin - (void)sayhello:(cdvinvokedurlcommand*)command; - (void)callresult:(nsstring*)response; @end
sayhello.m
#import "sayhelloplugin.h" #import "myconnectlistener.h" cdvinvokedurlcommand *tempcommand; @implementation sayhelloplugin - (void)sayhello:(cdvinvokedurlcommand*)command { myconnectlistener *connectlistener = [[myconnectlistener alloc] init:self]; [[wlclient sharedinstance] wlconnectwithdelegate:connectlistener]; tempcommand = command; } -(void)callresult:(nsstring*)response{ cdvpluginresult *pluginresult = [cdvpluginresult resultwithstatus:cdvcommandstatus_ok messageasstring:response]; [self.commanddelegate sendpluginresult:pluginresult callbackid:tempcommand.callbackid]; } @end
myconnectlistener.h
#import <foundation/foundation.h> #import "wlclient.h" #import "wldelegate.h" #import "sayhelloplugin.h" @interface myconnectlistener : nsobject <wldelegate> { @private sayhelloplugin *sh; } - (id)init: (sayhelloplugin *)sayhello; @end
myconnctlistener.m
the responsetext
line commented out because data retrieved adapter large suppose, it's best return need , not of it.
#import "myconnectlistener.h" #import "wlresourcerequest.h" nsstring *resulttext; nsstring *request; @implementation myconnectlistener - (id)init: (sayhelloplugin *) sayhello{ if ( self = [super init] ) { sh = sayhello; } return self; } -(void)onsuccess:(wlresponse *)response{ nsurl* url = [nsurl urlwithstring:@"/adapters/testadapter/getstories"]; wlresourcerequest* request = [wlresourcerequest requestwithurl:url method:wlhttpmethodget]; [request setqueryparametervalue:@"['technology']" forname:@"params"]; [request sendwithcompletionhandler:^(wlresponse *response, nserror *error) { if(error != nil){ resulttext = @"invocation failure: "; resulttext = [resulttext stringbyappendingstring: error.description]; [sh callresult:resulttext]; } else{ resulttext = @"invocation success. "; //resulttext = [resulttext stringbyappendingstring:response.responsetext]; [sh callresult:resulttext]; } }]; } -(void)onfailure:(wlfailresponse *)response{ resulttext = @"connection failure: "; resulttext = [resulttext stringbyappendingstring:[response errormsg]]; nslog(@"***** failure response: %@", resulttext); [sh callresult:resulttext]; } @end
Comments
Post a Comment