Note that there are some explanatory texts on larger screens.

plurals
  1. POobjC/C- combined: letting a C function wait till an objC-Delegate is finished
    text
    copied!<p>I'm having a problem here:</p> <p>I have a C function:</p> <pre><code>int my_connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; alertViewDelegate = [FirewallRest alloc]; [alertViewDelegate retain]; //ALog(@"1"); int error; //ALog(@"2"); char hostname[NI_MAXHOST] = ""; //ALog(@"3"); error = getnameinfo(serv_addr, addrlen, hostname, NI_MAXHOST, NULL, 0, 0); //ALog(@"4"); if (error !=0) { ALog(@"coudldn't resolve hostname or internal connect"); [pool release]; return orig__connect(sockfd, serv_addr, addrlen); } if (error == 0) { ALog(@"hostname: %s", hostname); NSString *hostFirst = [NSString stringWithCString:hostname]; NSString *host = [hostFirst stringByReplacingOccurrencesOfString:@"www." withString:@""]; NSString *msg = [@"tries to contact: " stringByAppendingString:host]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"asdf" message:msg delegate:alertViewDelegate cancelButtonTitle:@"Never allow!" otherButtonTitles:@"1", @"2",@"3", nil]; [alert show]; [alert release]; waitingForResponse = YES; while (waitingForResponse == YES) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; ALog(@"running Loop1?"); [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; ALog(@"running Loop2?"); [pool drain]; } ALog(@"continues"); return orig__connect(sockfd, serv_addr, addrlen); ... </code></pre> <p>It should wait till the UIAlertViewDelegate method (in it's own class) sets waitingForResponse == NO.</p> <pre><code>extern BOOL waitingForResponse; @implementation FirewallRest - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { //NSLog(@"buttonIndex: %@", buttonIndex); if (buttonIndex == 0){ NSLog(@"0"); waitingForResponse = NO; } if (buttonIndex == 1){ NSLog(@"1"); waitingForResponse = NO; } if (buttonIndex == 2){ NSLog(@"2"); waitingForResponse = NO; } if (buttonIndex == 3){ NSLog(@"3"); waitingForResponse = NO; } } </code></pre> <p>but somehow that doesn't work :/</p> <p>does anyone have an idea? or a better way to do this? (I'm not very used to C and objC in one app ;))</p> <p>Thanks in advance for any help</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload