dispatch_after is limited to 10 seconds?

前端 未结 3 2042
南方客
南方客 2021-01-23 23:04

I\'m developing an app which is running in background. Sometimes I need to tell the user that something is happenning so I play a sound a certain number of times. To do that I m

3条回答
  •  一向
    一向 (楼主)
    2021-01-23 23:38

    I suspect that chaining asynch blocks to play sounds at regular intervals is a bit of an overkill. Perhaps something simpler along the following lines would be easier to understand and maintain:

    // To initiate the alarm:
    [self fiBGTemps: ALARM];
    
    - (void)fiBGTemps:(int)sender
    {
        switch (sender) {
           ...
           case ALARM:
               dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
                    int count = 0;
                    while (count < NUM_ALARM /* AND not interrupted by user? */) {
                        sleep(2);
                        AudioServicesPlaySystemSound(alarma);
                        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
                        count++;
                    }
                });
                break;
            ...
        }
    }
    

提交回复
热议问题