NSPOSIXErrorDomain Code=12 “Cannot allocate memory” in 3G network

后端 未结 2 1349
忘掉有多难
忘掉有多难 2021-02-06 16:27

I\'m trying to send a file on FTP server in my iPhone application. Everything seems to be okay in WiFi and GSM:EDGE network, but in 3G network an error appears (not always, but

2条回答
  •  礼貌的吻别
    2021-02-06 16:51

    Have resolved this error with using operation for request (NSMutableUrlConnection) with @autorelease{} for main function

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

提交回复
热议问题