How to stop MPMusicPlayerController from enabling screen locking

前端 未结 3 1516
逝去的感伤
逝去的感伤 2021-02-06 02:58

I have an application that requires the iPhone screen to remain active (or not, depending on user choice). I\'ve done this by disabling the application idle timer, which works

3条回答
  •  佛祖请我去吃肉
    2021-02-06 03:51

    You should simply turn off the idle timer. What I usually do in a viewcontroller that needs to stay 'awake' is this:

    - (void) viewWillAppear:(BOOL)animated
    {
        [[UIApplication sharedApplication] setIdleTimerDisabled: YES];
    }
    
    - (void) viewWillDisappear: (BOOL) animated
    {
        [[UIApplication sharedApplication] setIdleTimerDisabled: NO];
    }
    

    This will make sure the screen will not get locked due to user inactivity.

提交回复
热议问题