首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xcode中的ConnectionKit框架不适用于我

xcode中的ConnectionKit框架不适用于我
EN

Stack Overflow用户
提问于 2009-09-30 15:13:23
回答 3查看 1.7K关注 0票数 0

我曾尝试制作一个连接到ftp服务器的Cocoa应用程序。所有答案都建议使用connection Kit框架,但不知何故我不能使用它。当我编译框架并将其添加到我的xcode项目中并构建它时。我不能再运行应用程序了。我在左下角看到错误,说应用程序退出了,状态为5。

在解决了这个问题之后,现在我在尝试构建时得到了9个错误:(这里是复制粘贴)

代码语言:javascript
复制
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中找到)时:

代码语言:javascript
复制
//  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

所以我想知道我做错了什么。

EN

回答 3

Stack Overflow用户

发布于 2009-09-30 23:52:54

#import <连接/连接.h>

尝试删除这些空格。您不太可能有一个名为“Connection”的框架,其中包含一个名为“Connection.h”的头文件。

票数 2
EN

Stack Overflow用户

发布于 2009-09-30 15:38:17

您确定<Connection/Connection.h>正在导入您需要的所有内容(特别是定义AbstractConnection的文件)吗?

票数 1
EN

Stack Overflow用户

发布于 2009-11-04 13:17:12

我不知道您使用的是哪个版本,但至少在1.2.2版本中,连接符合协议CKAbstractConnection,而不是AbstractConnectionProtocol。我认为你在Google上找到的代码不适用于任何当前版本的Connection Kit。

顺便说一句,对我来说,1.2分支目前似乎工作得最好。是的,在使用此框架时,缺乏编译和文档编制的示例代码可能会非常令人沮丧。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1498756

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档