Notification Service Extension errors in iOS 12.1 with AVFoundation

Our app use notification service extension to play custom audio. It works fine before iOS12.0(include 12.0).

But when i upgrade to 12.1, and found it can't play custom audio in background.


1. We found it report error when call [AVAudioSession setActive:true error:&err], the error info is

Error Domain=NSOSStatusErrorDomain Code=561015905 "(null)"

https://developer.apple.com/documentation/avfoundation/avaudiosession/errorcode/cannotstartplaying


I'm sure our main app has the background mode property for audio.


2. When we use AVAssetExportSession to export AVMutableComposition to output an new m4a file, it report error too.

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16980), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x10550bba0 {Error Domain=NSOSStatusErrorDomain Code=-16980 "(null)"}}


3. If we use AVAudioPlayer to paly an mp3 file, it failed.



Can anyone help me?



Accepted Reply

Most extensions are not allowed to activate an audio session, and so cannot play audio or use speech synthesis. This wasn't being enforced consistently prior to iOS 12.1, but now it is.


Some extensions (such as notification content extensions) present UI to the user, and those are allowed to activate an audio session.


Background modes in info.plist are not allowed for app extensions (and will get your app rejected by App Review)

Replies

We have encountered this problem as same.

I also encountered this

I notice that apple add a background mode for extension, you need add a 'Required background mode ' into info.plist that use 'App plays audio or streams audio/video using AirPlay'.

I have tried this and added this field, which was rejected directly when submitted. Is there any other way?

I have submitted a report of this bug. No response for now.

have any document or links?

Have you solved this problem?

I have added the filed, but still can't play local mp3 file by AVFoundation. Have you solved this problem?

Have you solved the problem?I had the same problem,added"App plays audio or streams audio/video using AirPlay"I can't play it.

Any one solved it ?

We've encountered this problem too.


BTW, where is then "background mode" for extension?

Most extensions are not allowed to activate an audio session, and so cannot play audio or use speech synthesis. This wasn't being enforced consistently prior to iOS 12.1, but now it is.


Some extensions (such as notification content extensions) present UI to the user, and those are allowed to activate an audio session.


Background modes in info.plist are not allowed for app extensions (and will get your app rejected by App Review)

Have any link or document?

Can we use AVAssetReader to read file in Notification Service Extension when iOS version is 12.1 or later?