0

Je crée UIAlertView dans ma fonction, le problème est qu'il montre beaucoup de temps lorsque la fonction fonctionne, comment puis-je créer une déclaration if pour afficher une seule fois comme si UIAlertView montre pas montrer plus. en CLa vue d'alerte montre Beaucoup de temps pas une fois

- (void)showAlert { 

    _myAlertView = nil; 
    _myAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Call_On_Hold",nil) 
               message:NSLocalizedString(@"Please_Wait",nil) 
              delegate:self 
            cancelButtonTitle:NSLocalizedString(@"Close_call",nil) 
            otherButtonTitles:nil, nil]; 
    _myAlertView.tag = myAlertViewsTag; 

    [_myAlertView show]; 

} 
objectif

Voici la fonction que mon UIAlertView apparaissent continuellement au lieu d'une seule fois.

- (void) trafficTimerRun:(NSTimer*)theTimer 
{ 
    ++ trafficTimerTicks; 

    pjmedia_rtcp_stat stat; 

    if (!get_stream_info([call_id intValue], &stat)) { 
     return; 
    } 

    LogDebug(TAG_SIP, @"Got %d bytes on stream 0 (previous: %d)", stat.rx.bytes, prev_bytes); 

    if (stat.rx.bytes == prev_bytes) { 
     if (trafficTimerTicks >= 10) { 

      // Steve-note: Here we need to show a pop-up message when the call in on hold when the trafficTimerTicks run. 
      [self showAlert]; 

      LogError(TAG_SIP, @"No traffic received, hanging up"); 

      // [theTimer invalidate]; 
      // broken = YES; Steve note: The call shouldnt broke. 
      // [self hangup]; Steve note: The call shouldnt hangup. 
     } 
    } 
} 

merci à l'avance.

+0

Side -note: 'UIAlertView' est obsolète, utilisez' UIAlertController' à la place. –

Répondre

0

Utilisez un booléen:

bool alertIsShowing = false; 

et dans votre méthode de mise à jour mettre quelque chose comme ceci:

if (trafficTicks > 10){ 
if (!alertIsShowing){ 
    alertIsShowing = true; 
    [self showAlert]; 
    } 
} 

Puis, quand est rejeté votre alerte, réinitialiser votre booléenne:

alertIsShowing = false; 
+0

Salut @Johnny Rockex, mon UIAlertView rejeter automatiquement, j'ai essayé, mais cela ne fonctionne pas. – Steven

+0

Voulez-vous qu'il soit ignoré automatiquement sans intervention de l'utilisateur? Notre alertView n'appelle-t-il pas une méthode déléguée en cas de renvoi? –

+0

Non désolé pour malentendu, j'ai déjà écrit la fonction de rejeter l'UIAlertview, mais les choses que je veux que le Alertview doit montrer une fois pas 100 fois. :( – Steven