iOS 11 Drop URL Returning Nil

余生颓废 提交于 2020-01-15 04:54:25

问题


I have the following code I'm trying to use for dragging a URL from Safari into a collection view and just having it print the URL.

func collectionView(_ collectionView: UICollectionView, performDropWith coordinator: UICollectionViewDropCoordinator) {
    for item: UIDragItem in coordinator.session.items {
        item.itemProvider.loadItem(forTypeIdentifier: kUTTypeURL as String, options: nil, completionHandler: { (url, error) in
            if let myURL = url as? URL {
                print (myURL)
            }
        })
    }
}

Problem is the print (myURL) line never gets called and myURL is nil.

I'm not sure why this isn't working as session.hasItemsConforming(toTypeIdentifiers: [kUTTypeURL as String]) is true, so it seems like that code should work.

Any ideas how to fix this?

EDIT 1

Adding print (url); prints the following.

2017-08-08 14:05:38.917080-0600 _____[1351:289923] [Common] _BSMachError: port 9c0b; (os/kern) invalid capability (0x14) "Unable to insert COPY_SEND"
Optional(<62706c69 73743030 a3010203 5f101a68 74747073 3a2f2f77 77772e6d 61637275 6d6f7273 2e636f6d 2f50d104 05557469 746c655f 10384d61 63205275 6d6f7273 3a204170 706c6520 4d616320 694f5320 52756d6f 72732061 6e64204e 65777320 596f7520 43617265 2041626f 7574080c 292a2d33 00000000 00000101 00000000 00000006 00000000 00000000 00000000 0000006e>)

It also says url is type NSSecureCoding?. I used similar code for a share extension and that worked fine.

来源:https://stackoverflow.com/questions/45576496/ios-11-drop-url-returning-nil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!