应用程序处于空闲状态时,套接字未连接

时间:2015-05-16 10:02:15

标签: ios sockets appdelegate

当我的应用程序处于空闲状态1小时后,在websocket没有连接之后,我无法从服务器接收数据。请指导我正确的解决方案?

Appdelegate.m

   - (void)applicationDidEnterBackground:(UIApplication *)application
 {
   //Close websocket connection
  [[IXWebSocketDataManager sharedNetworkDataManager] closeWebSocket];
}


  - (void)applicationDidBecomeActive:(UIApplication *)application
{

//Websocket connection
if([[NSUserDefaults standardUserDefaults] boolForKey:@"isLoggedIn"]==YES)
{
    NSMutableDictionary *paramDict=[[NSMutableDictionary alloc] init];
    [paramDict setObject:@"fg" forKey:@"stage"];
    [paramDict setObject:@"1.0" forKey:@"app_version"];
    [[IXNetworkDataManager sharedNetworkDataManager] userPingDetails:paramDict];
    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];

    if(remoteHostStatus == NotReachable)
    {
    }
    else{
        [[IXNetworkDataManager sharedNetworkDataManager] startLoadingWithOutUI];
         [[IXWebSocketDataManager sharedNetworkDataManager] connectWebSocket];
    }

}

}

- (void)applicationWillTerminate:(UIApplication *)application
{
 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"isLoggedIn"];
 [[NSUserDefaults standardUserDefaults] synchronize];

}

0 个答案:

没有答案