2013-04-29 78 views
0

我想通過webview實現照片上傳系統。響應AJAX調用iOS UIWebView

我讓它通過Safari瀏覽器工作,但尚未通過webview工作。我的研究使我意識到我需要使用的UIImagePickerController以捕獲映像文件的路徑,並且有這樣的方法:

- (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); 
    } 
} 

不過,我有麻煩工作如何我攔截和Ajax調用響應通過UIImagePickerController。

+0

相似的問題:http://stackoverflow.com/q/9889023/308315 – iwasrobbed 2013-04-29 15:21:50

+0

謝謝,我沒有在我的搜索過程中遇到這個職位。現在將閱讀。 – Enbee 2013-04-29 15:26:20

回答

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開發人員相當新穎的簡單監督,但也許這會幫助處於類似情況的人。

如果有人能詳細說明或整理我的代碼/說明,請做!