앱 내에서 FTP 연결을 설정하려고합니다. 하나의 디렉토리에있는 모든 파일을 FTP 서버에 업로드하고 싶습니다. 그래서 처음에는 원격 디렉토리를 만들고 싶습니다.iphone에서 ftp를 통해 백그라운드에서 파일 업로드
- (void) createRemoteDir {
NSURL *destinationDirURL = [NSURL URLWithString: uploadDir];
CFWriteStreamRef writeStreamRef = CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) destinationDirURL);
assert(writeStreamRef != NULL);
ftpStream = (__bridge_transfer NSOutputStream *) writeStreamRef;
BOOL success = [ftpStream setProperty: ftpUser forKey: (id)kCFStreamPropertyFTPUserName];
if (success) {
NSLog(@"\tsuccessfully set the user name");
}
success = [ftpStream setProperty: ftpPass forKey: (id)kCFStreamPropertyFTPPassword];
if (success) {
NSLog(@"\tsuccessfully set the password");
}
ftpStream.delegate = self;
[ftpStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
// open stream
[ftpStream open];
}
다음 호출 사용하여 백그라운드 스레드에서 실행될 때이 코드는 작동하지 않습니다
[self performSelectorInBackground: @selector(createRemoteDir) withObject: nil];
내 생각은 (배경 - 스레드) runloop이 실행되지 않는 것입니다? 내가 메인 스레드 내부에 메시지를 보낼 경우 은 업로드가 잘 작동 : 메인 스레드의 runloop가 실행입니다
[self createRemoteDir];
한다.
하지만 상당히 큰 파일이 업로드됩니다. 그래서 그 작업 부하를 배경 스레드에 넣고 싶습니다. 하지만 NSRunLoop을 어떻게 그리고 어디에서 설정해야합니까? 그래서 전체 업로드가 백그라운드 스레드에서 발생합니까? NSRunLoops의 사과 문서 (특히이 경우 타이머/입력 소스를 사용하지 않고 시작하는 방법)가 도움이되지 않았습니다.
나는 비슷한 질문을 여기에서 발견했다; 정말 코드가 솔루션에 대한 사용을보고 싶습니다 : [링크] (http://stackoverflow.com/questions/4930957/nsstream-and-sockets-nsstreamdelegate-methods-not-being-called) –