iOS 6 EXC_BAD_ACCESS in SampleFTPSample code

2019-04-12 07:33发布

I run the SampleFTPSample source code (iOS6.0 SDK, Xcode4.5)which downloaded from iOS Developer Center. SampleFTPSample

as the Images, when I retrieved a list from ftpServer, sometimes will get EXC_BAD_ACCESS error. I have not modified the code, I don't know why, and How can I fixed it?

Thank you very much.

EXC_BAD_ACCESS Fig.1 EXC_BAD_ACCESS Fig.2 EXC_BAD_ACCESS Fig.3

3条回答
混吃等死
2楼-- · 2019-04-12 08:10

yeahh!! I finally got the solution. I invoked uialertview show after main thread gets finish.So that it wont crash now. It is in mine case. So don't have an exact answer but you can also apply this peterlawn. May be it will be usefull to you to as well. !!

查看更多
神经病院院长
3楼-- · 2019-04-12 08:27

do this by setting the kCFStreamPropertyFTPAttemptPersistentConnection property to false, immediately after creating the stream (using CFReadStreamCreateWithFTPURL). Here's what that might look like:

 success = [self.networkStream setProperty:(__bridge id) kCFBooleanFalse
    forKey:(__bridge NSString *) kCFStreamPropertyFTPAttemptPersistentConnection
];
assert(success);
查看更多
孤傲高冷的网名
4楼-- · 2019-04-12 08:35
- (void)_startReceive:(NSString*) urlPath
{
BOOL                success;
NSURL *             url;
CFReadStreamRef     ftpStream;

assert(self.networkStream == nil);      // don't tap receive twice in a row!

// First get and check the URL.

if(urlPath != nil)
{
   ...url = FTP_URL here... 
}
success = (url != nil);
// If the URL is bogus, let the user know.  Otherwise kick off the connection.
if ( ! success) 
{
    [self _updateStatus:@"Invalid URL"];
} 
else 
{

    // Create the mutable data into which we will receive the listing.

    self.listData = [NSMutableData data];
    assert(self.listData != nil);

    // Open a CFFTPStream for the URL.

    ftpStream = CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url);
    assert(ftpStream != NULL);

    self.networkStream = (__bridge NSInputStream *) ftpStream;



    success = [self.networkStream setProperty:(__bridge id) kCFBooleanFalse
    forKey:(__bridge NSString *) kCFStreamPropertyFTPAttemptPersistentConnection
               ];
    assert(success);


    self.networkStream.delegate = self;
    [self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop]forMode:NSDefaultRunLoopMode];
    [self.networkStream open];

    // Have to release ftpStream to balance out the create.  self.networkStream 
    // has retained this for our persistent use.

    CFRelease(ftpStream);

    // Tell the UI we're receiving.

    [self _receiveDidStart];
}

}

查看更多
登录 后发表回答