2017-07-11 7 views
0

私は、アプリケーションの更新されたパラメータを収集する前にネットワーク接続を再確立する再開機能を持っています。Funcを続行する前に、ネットワーク接続が完了するのを待っていますか?

問題は、ネットワークリンクが再確立される前にいくつかのパラメータを取得しようとしているようです。

接続が確立されるまで一時停止できる方法はありますか?

getParametersのfuncが使用してバックグラウンドスレッドである:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^(void) { //code } 

initConnectionは、プライマリスレッドここ

ですFUNCです:

- (void)screenUnlocked { 
    [self initConnection]; 

    CDCChannelCollectionView *scrollView; 

    if ([self channelView]) { 
     scrollView = [[self channelView] scrollView]; 
     for (CDCChannelStrip* strip in [scrollView visibleCells]) { 
      [self getParameters:[NSNumber numberWithInteger:strip.channelNumber]]; 
     } 
    } 
} 

編集:

何かのようにこの?あなたが続くことができるブロック構文について

- (void)initConnection: completion:(void (^)(void))completionBlock { 
    if (![self isDemo]) { 
     [self setTcpControl:[[CDCControl alloc] initWithAddress:[self IPAddress] usingProtocol:TCP]]; 
     [[self tcpControl] setDelegate:self]; 
     [self setUdpControl:[[CDCControl alloc] initWithAddress:[self IPAddress] usingProtocol:UDP]]; 
     [[self udpControl] setDelegate:self]; 

     if (successful) { 
      completionBlock(); 
     } 
    } 
} 
+0

関数を呼び出す
//Block funtion with void block return type. - (void)initConnection:(void(^)(void))completionBlock { if (![self isDemo]) { [self setTcpControl:[[CDCControl alloc] initWithAddress:[self IPAddress] usingProtocol:TCP]]; [[self tcpControl] setDelegate:self]; [self setUdpControl:[[CDCControl alloc] initWithAddress:[self IPAddress] usingProtocol:UDP]]; [[self udpControl] setDelegate:self]; if (successful) { //call completion when connection is made. completionBlock(); } } } 

としてそのブロックであなたのUIを更新してください(メインキューに戻すことを忘れないでください) – Paulw11

+0

私はそれを試しましたが、正しく動作するように構文を試していました。 – jcad

+0

http://goshdarnblocksyntax.comを参照してください – Paulw11

答えて

0

:あなたは、ネットワーク操作があるときに呼び出される `initConnection`に完了ハンドラブロックを提供する必要があります

//Calling initConnection funtion. 
    [self initConnection:^{ 

     NSLog(@"complition success"); 
    }]; 
関連する問題