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

后端 未结 2 1350
忘掉有多难
忘掉有多难 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;
    
    }
    
    0 讨论(0)
  • 2021-02-06 17:05

    And here it is - the solution (or rather workaround):

    you should set property of writeStream to false, to switch off default persistant connection

    CFWriteStreamSetProperty( (CFWriteStreamRef)writeStreamRef, kCFStreamPropertyFTPAttemptPersistentConnection, kCFBooleanFalse ) ;
    
    0 讨论(0)
提交回复
热议问题