GCDAsyncSocket VOIP Background

I am trying to implement this (Configuring sockets to use VoIP) using this (CocoaAsyncSocket). As far as I know, step 1, which I did, adding VOIP to the background services in plist, and below should be step 2 (Configure one of the application sockets to use VoIP)

- (void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)connectedPort
{
    [CCV setLocalMode:FALSE];

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

But I cannot understand the rest of the steps. If i do

- (void)applicationDidEnterBackground:(UIApplication *)application
{
     expirationHandler = ^{

          [app endBackgroundTask:bgTask];
          bgTask = UIBackgroundTaskInvalid;


          bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler];
     };

     bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler];


     // Start the long-running task and return immediately.
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

          while (1) {
               sleep(1);               
               //NSLog(@"BGTime left: %f", [UIApplication sharedApplication].backgroundTimeRemaining);

               if ([rootViewController isIncomingCall] && showedCall != TRUE) {
                    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
                    if (localNotif) {
                         localNotif.alertBody = [NSString stringWithFormat:@"Incoming Call."];
                         localNotif.alertAction = NSLocalizedString(@"Accept Call", nil);
                         localNotif.soundName = @"alarmsound.caf";
                         //                         localNotif.applicationIconBadgeNumber = 1;
                         [application presentLocalNotificationNow:localNotif];
                         [localNotif release];
                    }
                    showedCall = TRUE;
               }
          }  
     });      

}

10 , . 2 : ( ) keepalive 5 . , . , apple " , VoIP-, , . , iOS setKeepAliveTimeout:handler: UIApplication" , - keepalive, , 600 ? , , , , , , .

+3
2

, , 100%. 21

2:

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

3:

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

     inProgram = FALSE;
     showedCall = FALSE;

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

}

, , , .

- (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;

               }               
          }
     }
}

: "" , Apple

plist

+2

, ,

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

- , , , , LOCKED didEnterBackground, 10-15 , ,

+1

Source: https://habr.com/ru/post/1761930/


All Articles