https://kotlinlang.org logo
#compose-ios
Title
# compose-ios
a

Ahmed Mourad

10/17/2023, 2:41 AM
Hello, I'm trying to implement the ios media picker by following the docs here: https://developer.apple.com/documentation/mediaplayer/displaying_a_media_picker_from_your_app 🧵
I've added these to my info.plist:
Copy code
<key>NSAppleMusicUsageDescription</key>
<string>...</string>
and this's the picker implementation:
Copy code
class RingtonePickerController(
    private val parent: UIViewController
) : NSObject(), MPMediaPickerControllerDelegateProtocol {

    private var mediaPicker: MPMediaPickerController? = null

    fun showRingtonePicker() {
        mediaPicker = MPMediaPickerController(MPMediaTypeAnyAudio)
        mediaPicker?.delegate = this
        mediaPicker?.allowsPickingMultipleItems = false
        parent.presentViewController(mediaPicker!!, animated = false, completion = null)
    }

    override fun mediaPickerDidCancel(mediaPicker: MPMediaPickerController) {
        mediaPicker.dismissViewControllerAnimated(true, completion = null)
    }

    override fun mediaPicker(mediaPicker: MPMediaPickerController, didPickMediaItems: MPMediaItemCollection) {
        val selectedItems = didPickMediaItems.items()
        // Do something with the selected media items

        mediaPicker.dismissViewControllerAnimated(true, completion = null)
    }
}
it doesn't work tho for some reason? whenever I call the showRingtonePicker method the ui will freeze for a second indicating that something is being pushed in front of my current controller, but then it just goes back to normal with nothing happening
I'm using a single swift uiviewcontroller that has a single child composable uiviewcontroller embedded into it
any ideas? thank you
I've tried using both the uiviewcontrollers as the parent, neither of them worked
a

Andrei Salavei

10/17/2023, 9:36 AM
Do you have something in the application log? Usually it tells what was wrong.
a

Ahmed Mourad

10/17/2023, 12:35 PM
@Andrei Salavei nope, nothing there
c

Cherrio LLC

10/17/2023, 10:16 PM
How are you using this class in
iosMain
?
a

Ahmed Mourad

10/18/2023, 2:25 AM
@Cherrio LLC what do you mean?
c

Cherrio LLC

10/18/2023, 6:22 AM
Sorry… I thought you were wrapping it within compose.
5 Views