GCDAsyncSocket background VOIP

本小妞迷上赌 提交于 2019-12-03 01:53:53

so i believe i have resolved the issue but need further testing to be 100% sure. Currently i ran a test with this code for the length of 21mins of suspended time and it worked

step 2:

 [socket performBlock:^{
                 [socket enableBackgroundingOnSocket];
             }];

step 3:

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

     inProgram = FALSE;
     showedCall = FALSE;

     BOOL backgroundAccepted = [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }];
     if (backgroundAccepted)
     {
          NSLog(@"VOIP backgrounding accepted");
     }

}

this seems to keep my client running so from here i add an observer to wait for my incoming call packet and launch a notification when that packet is seen

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{  
     if ([keyPath isEqualToString:@"currentDigitalJoin"]) 
     {
          switch ([[cClient currentDigitalJoin]intValue]) 
          {  
               case 1000: 
               {   
                    if (showedCall != TRUE && inProgram != TRUE) {
                         NSLog(@"incoming audio call");
                         UILocalNotification *localNotif = [[UILocalNotification alloc] init];
                         if (localNotif) {
                              localNotif.alertBody = [NSString stringWithFormat:@"Incoming Call."];
                              localNotif.alertAction = NSLocalizedString(@"Accept Call", nil);
                              localNotif.soundName = @"alarmsound.caf";
                              [app presentLocalNotificationNow:localNotif];
                              [localNotif release];
                              showedCall = TRUE;
                         }
                    }
                    break;
               }
               case 602: 
               {   
                    if (showedCall != TRUE && inProgram != TRUE) {
                         NSLog(@"incoming audio call");
                         UILocalNotification *localNotif = [[UILocalNotification alloc] init];
                         if (localNotif) {
                              localNotif.alertBody = [NSString stringWithFormat:@"Incoming Call."];
                              localNotif.alertAction = NSLocalizedString(@"Accept Call", nil);
                              localNotif.soundName = @"alarmsound.caf";
                              [app presentLocalNotificationNow:localNotif];
                              [localNotif release];
                              showedCall = TRUE;
                         }
                    }
                    break;
               }
               case 513: 
               {   
                    showedCall = FALSE;
                    break;
               }
          }
     }else if([keyPath isEqualToString:@"currentDigitalJoin"])
     {
          switch ([[cClient currentDigitalJoin]intValue]) 
          { 
               case 602: 
               {   
                    showedCall = FALSE;
                    break;

               }               
          }
     }
}

NOTE: the "step"s indicated are in reference to the steps indicated on the apple documentation

also dont forget to set the require wireless in the plist file

I realise this is an old question now - but you should call

 BOOL backgroundAccepted = [[UIApplication sharedApplication] setKeepAliveTimeout:600 handler:^{ [self backgroundHandler]; }];
 if (backgroundAccepted)
 {
      NSLog(@"VOIP backgrounding accepted");
 }

On app startup and use it all the time - the reason is, as you'll discover, is when the app is foregrounded, but the screen is LOCKED you don't receive the didEnterBackground call, and your app will be put to sleep 10-15 mins after the screen has locked, even though you are foregrounded

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!