라벨이 play인 게시물 표시

음악 플레이 하는 도중에 앱을 실행하면 중단되지 않도록 하는 방법 조치기

음악이나 라디오 또는 팟캐스트를 들으면서 교대근무 같은 앱을 실행하면 음악이 중단이 된다. 예전에는 아래 코드를 AppDelegate에 넣으면 중단되지 않고 내 앱에서 버튼 효과음까지 같이 실행되었었다. do {     try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)     try AVAudioSession.sharedInstance().setActive(true) } catch { print(error.localizedDescription) } 하지만 앱을 실행하면 중단이 될 뿐이었다. 각종 검색을 해보아도 위와 같은 코드만 나올 뿐이지 답은 없어 보였다. 이 때문에 xcode 도 제거하고 다시 설치 해보았다. 백그라운드 모드를 on 안 시켜서 그렇나? 역시나 마찬가지였다. 혹시나 하여 최근에 만들었던 다른 앱으로 구동해보았다. 음악이 중단되지 않고 버튼 효과음이 나올때 중단되는 것이다. 한줄기 희망을 보았다. 위의 코드를 메인뷰컨트롤러에 넣어 보았다. 역시나 중단이 된다. 혹시나 실행될때 위 코드로 실행을 했더니 중단이 되지 않는다. 각각의 효과음을 위 코드 블럭으로 싸고 실행하였다. 결과는 대성공이다. ㅋㅋㅋ guard let url = Bundle.main.url(forResource: "touch", withExtension: "mp3") else { return } do {     try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryAmbient)     try AVAudioSession.sharedInstance().setActive(true)     let touchPlayer = try AVAudioPlayer(contentsOf: url, fileTypeHint: AVFileType.mp