0

I am trying to implement a photo upload system via a webview.

I have it working via the safari browser, but have yet to get it working via the webview. My research has led me to realise I need to use UIImagePickerController in order to capture the image file path, and have this method:

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info   {

    NSString *path = [[NSBundle mainBundle] bundlePath];
    NSData *data = UIImageJPEGRepresentation( [info objectForKey:@"UIImagePickerControllerOriginalImage"] , 1.0);
    NSString *fullPath = [path stringByAppendingPathComponent:@"image_tmp.jpg"];
    if ([[NSFileManager defaultManager] createFileAtPath:fullPath contents:data attributes:nil] ) {
        NSLog([NSString stringWithFormat:@"file successfully written to path %@",fullPath],nil);
    }
}

However, I am having trouble working out how I intercept and respond to the ajax call via the UIImagePickerController.

4

1 回答 1

0

经过更多的实验,我已经找到了解决问题的方法。可以这么说,我似乎过度设计了这个问题。

我的 AJAX 调用需要简单地返回图像路径,其余的将在服务器端处理。我所有的研究都指出 UIImagePickerController 是返回图像路径所必需的,但实际上并非如此。

- (void)viewWillAppear:(BOOL)animated {

    if(animated){
        NSLog(@"YES");
    }else{
        NSLog(@"NO");
        NSString *url = [NSString stringWithFormat:@"http://www.mywebview.com/photo-upload.php"];
        [photoview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
        timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(tick) userInfo:nil repeats:YES];
    }   
}

通过使用 viewWillAppear 并为动画返回一个布尔值,我能够判断调用是用于页面加载还是 AJAX 调用。实际上是页面重新加载阻止了上传,文件路径一直在传递......对iOS开发相当陌生的人的简单监督,但也许这会对处于类似情况的人有所帮助。

如果有人可以详细说明或整理我的代码/解释,请做!

于 2013-04-29T19:14:34.447 回答