1

How to initiate call of handleRemoteNowPlayingActivity function.

I try to play an audio file with AVAudioPlayer in my iPhone app and I expect that this function will be called on watches.

Maybe I should make some additional call to trigger this function? I cannot find any additional information about this method except what is said in the apple documentation.

Maybe someone faced this problem and will be able to help me.

Code of initialization audio player.

@IBAction func play(_ sender: Any) {
        let url = URL(string: Bundle.main.path(forResource: "music", ofType: "mp3") ?? "")!

        do {
            try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: .mixWithOthers)
            try AVAudioSession.sharedInstance().setActive(true)
            player = try AVAudioPlayer(contentsOf: url)
        } catch let error {
            print(error)
        }
        player?.play()
    }

1 Answers1

1

I have found the answer.

If you want to initiate handleRemoteNowPlayingActivity in your watch app, you should

  • play some audio/video on your device

  • setup audio session as shown above

  • and call beginReceivingRemoteControlEvents().

  • My watchApp is launched in this case, but handleRemoteNowPlayingActivity() is not called in WKExtensionDelegate. Other delegate methods are being called. Have you figured it out? – Vitaly Oct 06 '21 at 07:35