我正在尝试为我的应用程序做一个Action扩展,用户可以在其中添加他当前的位置以及其他一些数据。在与Apple Maps应用程序共享了一个位置之后,我调试了这个扩展,发现Maps发送了四个提供程序,内容如下:
MKMapItem上面的所有内容都是NSSecureCoding类型的。强制转换为Data,并使用vCard的数据初始化String,将纯文本强制转换为String,url从NSSecureCoding获得成功,但我还没有找到从接收到的数据创建MKMapItem对象的方法。
以下是我尝试过的:
provider.loadItem(forTypeIdentifier: "com.apple.mapkit.map-item", options: nil) { (content, _) in
let item = content as! MKMapItem
}但失败了。我可能得先把它转换成Data,但是我找不到MKMapItem和Data的任何初始值
发布于 2019-03-27 23:19:38
使用NSKeyedUnarchiver
itemProvider.loadItem(forTypeIdentifier: "com.apple.mapkit.map-item", options: nil) { (item, error) in
guard let data = item as? Data else { return }
do {
guard let mapItem = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? MKMapItem else { return }
print(mapItem)
} catch {
print("Error unarchiving mapItems, \(error)")
}https://stackoverflow.com/questions/52219700
复制相似问题