我会做什么?
我希望能够在我自己的应用程序中共享文件 url,例如 whatsapp,即:
我在做什么?
从 Xcode 自行生成的应用程序开始
我猜关键词是
CFBundleDocumentTypes
。
所以我加了
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array/>
<key>CFBundleTypeName</key>
<string>All Files</string>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.data</string>
</array>
</dict>
</array>
到
Info.plist
。
通过这样做,myApp 能够从外部接收文件(例如从文件应用程序)。
然后我在
ViewController
中添加
@IBAction func share(_ sender: Any)
{
let url = Bundle.main.url(forResource: "blank", withExtension: "pdf")!
let activityViewController = UIActivityViewController(activityItems: [url], applicationActivities: nil)
// iPad
if let popover = activityViewController.popoverPresentationController
{
popover.sourceView = view
popover.sourceRect = CGRect(x: view.bounds.midX, y: view.bounds.maxY, width: 0, height: 0) //center bottom
}
activityViewController.isModalInPresentation = true
present(activityViewController, animated: true)
}
链接到
Button
.
问题
通过单击共享按钮,myApp 不会出现在列表中。
有什么好笑的?它适用于模拟器 - Xcode 14.3 RC 2.