0

How to check iOS APP [music play app] is on Background when APP is launched by the headset wire control?

or quick music play like this enter image description here

When we click on the quick song to play, in fact, the app has started and played the song, but the iOS system does not actively tell us that the program is in the background. In this case, how exactly do we know that the app is in the background and is separate from the normal home button background switch。 Or how do you distinguish this type of program startup

ganvinalix
  • 65
  • 5

1 Answers1

0

If you know when your app has started playing music (i.e. via a delegate method or callback or something), you can check the current state of the app by using UIApplication's applicationState property.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • But sometimes it's not really playing the song – ganvinalix Nov 28 '18 at 11:52
  • This sounds like a separate issue than the one you asked. Could you add a new question and include some code that shows what you do when the user asks to play music? – Michael Dautermann Nov 28 '18 at 11:54
  • Or to put it another way how do I distinguish this type of program startup? – ganvinalix Nov 28 '18 at 11:56
  • If this were my problem, I'd look at the launch dictionary in [`application(_:didFinishLaunchingWithOptions:)`](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622921-application) to see if it gives me a hint as to why my app was launched and it might say whether my app was launched from the [iOS Control Center](https://gizmodo.com/every-single-setting-in-ios-control-center-and-how-each-1824308937) (which is what you are looking at in your screenshot). – Michael Dautermann Nov 28 '18 at 12:09
  • I looked at that place and it was empty – ganvinalix Nov 29 '18 at 02:15