POSIX error 12 (“Cannot allocate memory”) while uploading files from an iPhone

前端 未结 3 1400
长情又很酷
长情又很酷 2021-02-08 15:59

I\'m working on an iPhone application that involves uploading full photos from the camera (generally between 1.5 to 2.0 MB each) as well as their thumbnails (much smaller) to Am

3条回答
  •  别那么骄傲
    2021-02-08 16:02

    Have resolved this error with using operation for request (NSMutableUrlConnection) with @autorelease{} for main function. NSPOXIS appears only sometimes.

    - (void)main
     NSURLConnection* connection;
        @autoreleasepool //urgently needed for 3G upload
        {
    
            self.currentRequest = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"test.php"]];
            [self.currentRequest setHTTPMethod:@"PUT"];
    
            [self.currentRequest setHTTPBody:self.data];//inpustStream doesn't work
    
            connection = [NSURLConnection connectionWithRequest:self.currentRequest delegate:self];
            [connection start];
    
        }//end autorelease pool
    
            do 
            {
    
                [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode beforeDate: [NSDate distantFuture]];
                if ([self isCancelled])
                {
                    connection          = nil;
                    isFailed = YES;
                    break;
                }
                self.status(statusUpdateMessage);
            } 
            while (!isFailed && !isCompleted);
            [timer invalidate];//test
            timer = nil;
    
    //corresponding of status via blocks
            self.completed(!isFailed);
            self.status(isFailed ? errorMessage : @"Completed");
            if (isFailed)
            {
                self.failed(errorMessage != nil ? errorMessage : @"Undefined error");
            }
    
            self.data = nil;
            self.currentRequest = nil;
    
            connection = nil;
    
    }
    

提交回复
热议问题