我试图创建一个连接到ftp服务器的Cocoa应用程序。 所有答案都建议使用连接套件框架但不知何故我无法使用它。 当我编译框架并将其添加到我的xcode项目并构建它。我不能再运行该应用程序了。我在左下角收到错误,说该应用已退出状态为5。
解决了这个问题之后,现在我在尝试构建时遇到了9个错误:( Heres copy paste)
AppDelegate.m:17: error: 'AbstractConnection' undeclared (first use in this function)
AppDelegate.m:50: error: syntax error before 'AbstractConnection'
AppDelegate.m:55: error: 'baseDirField' undeclared here (not in a function)
AppDelegate.m:56: error: syntax error before 'if'
AppDelegate.m:62: error: syntax error before 'AbstractConnection'
AppDelegate.m:69: error: syntax error before '}' token
AppDelegate.m:71: error: syntax error before 'AbstractConnection'
AppDelegate.m:75: error: syntax error before 'for'
AppDelegate.m:75: error: syntax error before '<' token
尝试使用以下代码时(在google中找到):
// AppDelegate.h
#import < Cocoa/Cocoa.h >
@protocol AbstractConnectionProtocol;
@interface AppDelegate : NSObject {
IBOutlet NSTextField *hostNameField;
IBOutlet NSTextField *usernameField;
IBOutlet NSTextField *passwordField;
IBOutlet NSTextField *baseDirField;
IBOutlet NSTextView *log;
IBOutlet NSTextField *status;
id <AbstractConnectionProtocol> con;
BOOL isConnected;
}
- (IBAction) connect:(id)sender;
- (IBAction) disConnect:(id)sender;
@end
// AppDelegate.m
#import "AppDelegate.h"
#import < Connection/Connection.h >
@implementation AppDelegate
- (IBAction) connect:(id)sender;
{
NSError *err = nil;
con = [[AbstractConnection connectionToHost:[hostNameField stringValue]
port:@"21"
username:[usernameField stringValue]
password:[passwordField stringValue]
error:&err] retain];
if (!con)
{
if (err)
{
[NSApp presentError:err];
}
return;
}
NSTextStorage *textStorage = [log textStorage];
[textStorage setDelegate:self]; // get notified when text changes
[con setTranscript:textStorage];
[con setDelegate:self];
[status setStringValue:[NSString stringWithFormat:@"Connecting to: %@", [hostNameField stringValue]]];
[con connect];
}
- (IBAction) disConnect:(id)sender;
{
if( con )
{
[con disconnect];
}
}
- (void)connection:(AbstractConnection *)aConn didConnectToHost:(NSString *)host
{
isConnected = YES;
[status setStringValue:[NSString stringWithFormat:@"Connected to: %@", host]];
NSString *dir = [[baseDirField stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (dir && [dir length] > 0)
[con changeToDirectory:[baseDirField stringValue]];
[con directoryContents];
}
- (void)connection:(AbstractConnection *)aConn didDisconnectFromHost:(NSString *)host
{
isConnected = NO;
[status setStringValue:[NSString stringWithFormat:@"Disconnected from: %@", host]];
[con release];
con = nil;
}
- (void)connection:(AbstractConnection *)aConn didReceiveContents:(NSArray *)contents ofDirectory:(NSString *)dirPath
{
NSLog(@"%@ %@", NSStringFromSelector(_cmd), dirPath);
int i = 0;
for (i=0; i < [contents count]; ++i) {
id object = [contents objectAtIndex:i];
[[[log textStorage] mutableString] appendFormat:@"%@\n", object];
}
}
@end
所以我想知道我做错了什么。
答案 0 :(得分:2)
#import < Connection/Connection.h >
尝试删除这些空格。您不太可能拥有名为“Connection”的框架,其中包含名为“Connection.h”的头文件。
答案 1 :(得分:1)
您确定<Connection/Connection.h>
正在导入您需要的所有内容(特别是定义AbstractConnection
的文件)吗?
答案 2 :(得分:0)
我不知道您使用的是哪个版本,但至少在1.2.2连接中符合协议CKAbstractConnection
,而不是AbstractConnectionProtocol
。我认为您在Google上找到的代码不适用于任何当前版本的Connection Kit。