Sha256: 751d75c671860a6bb2efa0924735c208d26df69da24d17751017abe86f3b5f38
Contents?: true
Size: 1.63 KB
Versions: 17
Compression:
Stored size: 1.63 KB
Contents
#import "JavascriptVMSingleton.h" @implementation JavascriptVMSingleton @synthesize webView; - (id) init { self = [super init]; if (self != nil) { [self performSelectorOnMainThread:@selector(perfromInit) withObject:nil waitUntilDone:YES]; } return self; } - (void) perfromInit { webView = [[UIWebView alloc] initWithFrame:CGRectZero]; } -(void) executeScript:(NSString*)script methodResult:(CMethodResult*)methodResult { NSMutableArray *args = [[NSMutableArray arrayWithCapacity:3] autorelease]; [args addObject:webView]; [args addObject:script]; [args addObject:[[NSString alloc] autorelease]]; [self performSelectorOnMainThread:@selector(executeScriptImpl:) withObject:args waitUntilDone:YES]; [methodResult setResult:[args objectAtIndex:2]]; } -(void) executeScriptAsync:(NSString*)script { NSMutableArray *args = [[NSMutableArray arrayWithCapacity:3] autorelease]; [args addObject:webView]; [args addObject:script]; [args addObject:[[NSString alloc] autorelease]]; [self performSelectorOnMainThread:@selector(executeScriptImpl:) withObject:args waitUntilDone:NO]; } - (void) executeScriptImpl:(NSMutableArray*)args { UIWebView* view = [args objectAtIndex:0]; NSString* js = [args objectAtIndex:1]; [args replaceObjectAtIndex:2 withObject:[view stringByEvaluatingJavaScriptFromString:js]]; } - (void) dealloc { if (webView) { [webView release]; } [super dealloc]; } @end
Version data entries
17 entries across 17 versions & 2 rubygems