我移植并大量修改了 BlackRaccoon。它旨在使用委托。换句话说,代表是必需的。
BRRequestCreateDirectory *createEventDir = [BRRequestCreateDirectory initWithDelegate:nil];
//NSString *EventCode = [[NSUserDefaults standardUserDefaults] stringForKey:kEventCodeKey];
createEventDir.path = @"/12341234";
createEventDir.hostname = @"media.example.com/httpdocs/events/";
createEventDir.username = @"badboy";
createEventDir.password = @"hai!";
createEventDir.tag = 103;
[createEventDir start];
createEventDir = nil;
是不正确的。它开始了很多事情,然后删除了对象 - 动作未定义。
相反,您需要我提供的代码中指示的东西(不会泄漏)。
首先,使用 ftp 的类需要有 BRRequestDelegate 来指示委托协议。
- (IBAction) createDirectory:(id)sender
{
//----- createEventDir must be a variable in your class...
createEventDir = [BRRequestCreateDirectory initWithDelegate: self];
createEventDir.path = @"/12341234;
createEventDir.hostname = @"media.example.com/httpdocs/events/";
createEventDir.username = @"badboy";
createEventDir.password = @"hai!";
[createEventDir start];
//----- createEventDir MUST NOT BE DELETED OR SET TO NIL HERE
}
然后你必须有两个代表(至少):
-(void) requestCompleted: (BRRequest *) request
{
//----- handle Create Directory
if (request == createEventDir)
{
NSLog(@"%@ completed!", request);
//----- everything is done, NOW you can set it to nil
createEventDir = nil;
}
}
-(void) requestFailed: (BRRequest *) request
{
if (request == createEventDir)
{
NSLog(@"%@", request.error.message);
//----- everything is done, NOW you can set it to nil
createEventDir = nil;
}
}
如果你回去看看我的测试代码,你会看到事情是如何工作的。如果您仍有问题,请在http://github.com/lloydsargent/BlackRaccoon上发布问题
希望这会让你克服你的问题。