NSInputStream in blocking mode

Discussion in 'iOS Programming' started by arnieterm, Dec 29, 2009.

  1. arnieterm macrumors regular

    Joined:
    Aug 28, 2008
    #1
    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
     
  2. robj macrumors regular

    Joined:
    Dec 23, 2009
    Location:
    Madrid, Spain
    #2
    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.
     
  3. arnieterm thread starter macrumors regular

    Joined:
    Aug 28, 2008
    #3
    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
     
  4. arnieterm thread starter macrumors regular

    Joined:
    Aug 28, 2008
    #4
    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
     
  5. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    Move the pushViewController call from within the button code to within the NSInputStream receiving delegate method.
     
  6. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #6
    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.
     

Share This Page