Passing value from xcode to my javascript uiwebview
I'm using UIWebView and call my web as follow
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *urlAddress = @"http://x.com/index.php/bla";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *reqObject = [NSURLRequest requestWithURL:url];
[webview loadRequest:reqObject];
webview.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
}
On that page, i call javascript file named script.js for processing image
taken from iphone camera
function processImage( img )
{
$('#task_result').empty();
$('#task_result').append( '<li><img id="testImage" src="' + img + '"
height="200px" width="200px" /></li>' );
}
should i load the script js to xcode project or i have to write on my page
as usual
<script src="http://x.com/js/script.js">
if i load the script to xcode project, do i have to save script js in my
server and still write as above to load the script?
on my xcode project, i have handler to process image picked up from iphone
camera as follows :
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info
objectForKey:@"UIImagePickerControllerOriginalImage"];
//flatten it to NSData as a JPEG, low quality
NSData *flatImage = UIImageJPEGRepresentation(image, 0.1f);
NSString *image64 = [flatImage base64EncodedString];
//process the image in javascript to be added to the page
NSString *js =
[NSStringstringWithFormat:@"processImage('data:image/jpeg;base64,%@')",
image64];
[self.webview stringByEvaluatingJavaScriptFromString:js];
//dismiss the image picker
[picker dismissViewControllerAnimated:YES completion:nil];
}
i'm facing difficulties to communicate with function processImage. So far
if I writedown
<script src="http://x.com/js/script.js">
without bundling script.js to my xcode project, the picture sometimes can
embed to my web page, but sometimes it can't work.
Is there any suggestion ? thanks.
No comments:
Post a Comment