我需要使用以下给定的 - (BOOL)方法连接imap电子邮件服务器
点击连接按钮后如何在IBACTION中调用此方法?
- (BOOL) connectToHost: (NSString*) hostname
{
socket_ = socket(AF_INET, SOCK_STREAM, 0);
if (socket_ < 0) {
NSLog(@"socket");
}
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
addr.sin_port = htons(993);
struct hostent* host = gethostbyname([hostname UTF8String]);
unsigned int** ptr = (unsigned int **) host->h_addr_list;
while (*ptr != NULL) {
addr.sin_addr.s_addr = *(*ptr);
if (connect(socket_, (struct sockaddr *) &addr, sizeof(addr)) == 0) {
break;
}
ptr++;
}
if (*ptr == NULL) {
NSLog(@"connect");
}
return [[self readLine] isEqualToString: @"* OK"];
}
答案 0 :(得分:3)
...从另一种方法调用它?
- (IBAction) connectButtonClicked:(id)sender {
[self connectToHost:@"Your host name goes here, variable _or_ constant! :D"];
}