我在 UINavigationController 上嵌入了一个视图。在这个视图上,ai 有一个按钮转发到 UITableViewController。当我到达 UINavigationcontroler 上的 UITableViewController 时,我添加了一个用于上传文件的按钮。文件上传操作在 dispatch_async 内部执行。当 dispatch_async 完成时,我添加了一个带有消息完成的 UIAlertView。有一个问题,因为我从 UINavigationController 的后退按钮和 dispatch_async 不完整,我的应用程序崩溃了。我在哪里做错了?在我的代码之后谢谢,文森佐
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0);
dispatch_async(queue, ^ {
BOOL success;
NSURL * url;
NSString *fileNameUrl = [@"ftp://xxx.xxx.xxx.xxx/" stringByAppendingString:nameFile];
url = [[NetworkManager sharedInstance]smartURLForString:fileNameUrl];
success = (url != nil);
if ( ! success) {
NSLog(@"Invalid URL");
} else {
self.fileStream = [NSInputStream inputStreamWithData:dataAsset];
assert(self.fileStream != nil);
[self.fileStream open];
self.networkStream = CFBridgingRelease(
CFWriteStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)
);
success = [self.networkStream setProperty:@"XXXX" forKey:(id)kCFStreamPropertyFTPUserName];
success = [self.networkStream setProperty:@"YYYYYY" forKey:(id)kCFStreamPropertyFTPPassword];
self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
[[NSRunLoop currentRunLoop]run];
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"SUCCESS" message:@"Complete" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[alertView show];
});
}
});