Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

arnieterm

macrumors regular
Original poster
Aug 28, 2008
201
0
For my iphone application that isusing NSStream. I need to use NSInputStream in UI blocking mode so that till the input stream arrives the UI remains blocked as this is my requirement. Though I have scheduled a runLoop to handle the various event types and I am getting these events too. The only problem is that I am not able to block the UI during the receipt.
How can I make NSInputStream/NSOutputStream as synchronous?.
The problem is that at the touch of a UIButton I initiates a streaming call and there is a UINavigationController being pushed at the end of the UIButton touch event code. But I receive the streaming event later and navigationController gets pushed. Instead of this I need to wait for stream to come and then push the navigation controller after that
 
I'm not sure if it does fit you, but take a look to:

performSelectorOnMainThread

For example:
Code:
[self performSelectorOnMainThread:@selector(methodName) withObject:argument waitUntilDone:YES]

This should invoke that method in the main thread, making it a blocking call.
 
Thanks for the reply.
I have already given this method a try but my

Code:
- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode

is not getting called. In the UIButton touch event I have written this.
Code:
[NSThread detachNewThreadSelector: @selector(loginThread) toTarget: self withObject: nil];
In the loginThread method just above [pool release] call I have used the code as mentioned in your reply but that handler does not gets called.

Any other thing to use instead?
Thanks
Arnieterm
 
The simplest way I so far is to use the below given thing
Code:
[iStream setDelegate: nil];
[oStream setDelegate: nil];

After this we can use a while loop to check for if the output screen has space available and input screen for has bytes available
 
The problem is that at the touch of a UIButton I initiates a streaming call and there is a UINavigationController being pushed at the end of the UIButton touch event code.
Move the pushViewController call from within the button code to within the NSInputStream receiving delegate method.
 
Don't block the UI. You are trying to do too much inside one event handler. Split it up into multiple handlers. Have another event handler, notification receiver or delegate push the view after everything that is needed is ready.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.