Last active
December 16, 2015 14:28
-
-
Save rossmartin/5448596 to your computer and use it in GitHub Desktop.
Return file contents to JavaScript from Objective-C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void) restClient:(DBRestClient*)client loadedFile:(NSString*)localPath { | |
NSLog(@"File loaded into path: %@", localPath); | |
NSData *fileData; | |
fileData = [NSData dataWithContentsOfFile:localPath]; | |
if (!fileData){ | |
NSLog(@"Error - File not found"); | |
} | |
NSString* fileString = [[NSString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; | |
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; | |
NSString *jsCallback = [[NSString alloc] initWithFormat:@"showFileContents('%@')", fileString]; | |
[appDelegate.viewController.webView stringByEvaluatingJavaScriptFromString:jsCallback]; // this calls showFileContents function in JS and sends it the fileString as a parameter | |
[self writeJavascript:restoreJavaScript]; // return code to execute JavaScript function after file is downloaded | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment