iOS 11 dropInteraction performDrop for files

后端 未结 2 1963
日久生厌
日久生厌 2020-12-17 17:55

How can I use dropInteraction(_ interaction: UIDropInteraction, performDrop session: UIDropSession) to accept other type of files than images? Say for instnce t

2条回答
  •  太阳男子
    2020-12-17 18:29

    Within dropInteraction you call session.loadObjects(ofClass:), which you probably already have, and have tried UIImage and NSURL.

    ofClass needs to conform to NSItemProviderReading (Documentation). The default classes that conform to it are NSString, NSAttributedString, NSURL, UIColor, and UIImage. For anything else, I think you will need to make a custom class conforming to the protocol, using public.mp3 as the UTI. Your custom class will have a init(itemProviderData: Data, typeIdentifier: String) initializer that should give you a bag of bytes (itemProviderData) that is the MP3s data. From there, you should be able to write out your file as needed.

提交回复
热议问题