2012-04-25 21 views
0

現在、画像を撮影してサーバーにアップロードできるiOSアプリケーションを開発中です。XCodeサーバーに画像を送信する

私はシミュレータでうまく動作しますが、デバイスのテストでは受信したメモリの警告が表示され、クラッシュします。

私はちょうど私の問題に関連しているビットを表示しようとするでしょう私のコードではかなり多くあります:

私はデバイス上のこの写真ピッカーを使用して撮影した2枚の画像を送信しようとしています携帯電話に保存され、決済画面に通過している:決済画面で

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
    { 
     UIImage *image=[info objectForKey:@"UIImagePickerControllerOriginalImage"]; 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
     NSString* path = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithString: "name.jpg"] ]; 
     NSData* data = UIImageJPEGRepresentation(image,1.0); 
     [data writeToFile:path atomically:YES]; 
    } 

私は、サーバーとPHPスクリプトに送信するには、このコードを持っているPayPalのサービスを送り返す:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString* path = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithString: @"name.jpg"] ]; 

    NSData *imageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:path]); 


    NSString *urlString = @"http://server.com/payment.php?"; 
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; 
    [request setURL:[NSURL URLWithString:urlString]]; 
    [request setHTTPMethod:@"POST"]; 

    NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; 
    NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary]; 
    [request addValue:contentType forHTTPHeaderField:@"Content-Type"]; 

    NSMutableData *body = [NSMutableData data]; 

    [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithString:@"Content-Disposition: form-data; name=\"backfile\"; filename=\"back.jpg\"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[[NSString stringWithString:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; 
    [body appendData:[NSData dataWithData:imageData]]; 
    [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 

    [webView loadRequest:request]; 


    [self.view addSubview:webView]; 
    [request setHTTPBody:body]; 

申し訳ありませんがあまりにも明確でない場合は、私にお知らせください。それはサーバーに画像を送信しますが、アプリケーションではプロセスがクラッシュします。私は画像のサイズを変更しようとしましたが、可能な限り最高の品質でそれらを必要としています。私は縮小画像を使用して送信する場合:

UIGraphicsBeginImageContext(frontSize); 
    [frontimg drawInRect:CGRectMake(0,0,242,444)]; 
    UIImage* realfrontImage = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 
    NSData *frontImageData = UIImageJPEGRepresentation(image, 1.0); 

を私は周りに300

任意の助けをそれを必要とするときしかし画質が72PPIで働くいただければ幸いです。

答えて

0

投稿を行うにはwebviewを使用するのは珍しいことです。 webview(または他の何かが必須)がメモリ警告で解放されている可能性があります。これで置き換えて助けてくれますか?

NSOperationQueue *queue = [[NSOperationQueue alloc] init]; 

[NSURLConnection request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) 
{ 
    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response; 
    NSLog(@"got response %d, data = %@, error = %@", [httpResponse statusCode], data, error); 
}]; 
+0

私の解決策は、この回答にあります。別々の投稿に両方の画像をアップロードしてから、画像サイズに問題があり、年齢がかかります。 – chrisw

0

ごUIViewControllersはあなたが依存しているオブジェクトを解放しているかどうかを確認するためにあなたの方法をdidReceiveMemoryWarning UIViewControllersとviewWillUnload方法の全てにのNSLogのデバッグメッセージを追加します。

関連する問題