RestKit コールバック内から呼び出された場合、PhoneGap コールバックが機能しないようです。RestKit 呼び出しを削除することで、PhoneGap コールバック ロジックが正常に機能することを検証しました (さらに、他のすべての PhoneGap プラグイン コールバックが正常に機能します)。以下のコードでは、RestKit 呼び出しの完了時に loader.onDidLoadResponse が実行されますが、PhoneGap / Cordova コールバック行が実行されても、javascript の対応する完了ルーチンは実行されません。まるでコールバックが消えたかのようです。コンテキストや、RestKit や PhoneGap 非同期ロジックの記述方法に何か問題がありますか?
どんな助けでも大歓迎です。
-(void)GetRestJson:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSString* callbackID = [arguments pop];
NSLog(@"%@",callbackID);
NSString* url = [arguments objectAtIndex:0];
NSString* sublocation = [arguments objectAtIndex:1];
NSDictionary * args = [NSDictionary dictionaryWithObjectsAndKeys:
callbackID, @"callBackID",
self, @"thisObject",
nil];
RKClient* client = [RKClient clientWithBaseURL:[RKURL URLWithString:url]];
// <---- RESTKIT CALL MADE (WORKS)
[client get:sublocation usingBlock:^(RKRequest* loader)
{
loader.onDidLoadResponse = ^(RKResponse *response) // <---- RESTKIT COMPLETION CALLED (WORKS)
{
NSString* result = [response bodyAsString];
NSString * callbackID = [args objectForKey:@"callBackID"];
id callingObject = [args objectForKey:@"thisObject"];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString: [result stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[callingObject writeJavascript: [pluginResult toSuccessCallbackString:callbackID]]; // <---- PHONEGAP CALLBACK MADE (BROKEN --- DOESN'T ARRIVE BACK ON JS CALLBACK)
};
loader.onDidFailLoadWithError = ^(NSError *error)
{
NSString* result = [error description];
NSLog(@"Loaded payload: %@", result);
NSString * callbackID = [args objectForKey:@"callBackID"];
id callingObject = [args objectForKey:@"thisObject"];
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString: [result stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[callingObject writeJavascript: [pluginResult toErrorCallbackString:callbackID]];
};
}];
}