我UIDocumentInteractionController用于文件预览:
interactionController = UIDocumentInteractionController.FromUrl(url);
interactionController.Delegate = new UIDocumentInteractionControllerDelegateClass(this);
InvokeOnMainThread(delegate{interactionController.PresentPreview(true);}
});
Run Code Online (Sandbox Code Playgroud)
如何在视图顶部添加自定义按钮以执行某些操作?
我.stl在iOS上打开文件UIDocumentInteractionController.我看到以下选项:

现在,如果我选择Mail,它会自动将.stl文件附加到电子邮件中.没关系.
但如果我安装了另一个支持.stl文件的应用程序(例如MeshLab),那么我看到以下内容:

如果我再次选择邮件 - 它将不再将文件附加到电子邮件中.
为什么会这样(为什么文件没有附加到第二种情况下的电子邮件)?有没有办法改变这种行为?
PS我正在使用Xamarin.iOS,但在这种情况下认为不重要.
我实现了MPMediaPickerController
- (IBAction)pickSong:(id)sender {
MPMediaPickerController *picker =
[[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];
picker.delegate = self;
picker.allowsPickingMultipleItems = NO;
picker.prompt = NSLocalizedString (@"Select any song from the list", @"Prompt to user to choose some songs to play");
picker.showsCloudItems = YES;
[self presentModalViewController: picker animated: YES];
}
- (void) mediaPicker: (MPMediaPickerController *) mediaPicker didPickMediaItems: (MPMediaItemCollection *) mediaItemCollection
{
[self dismissModalViewControllerAnimated: YES];
if (mediaItemCollection.count > 0) {
MPMediaItem *mediaItem = [mediaItemCollection.items objectAtIndex:0];
NSLog(@"%@ - %@, %@", [mediaItem valueForProperty:MPMediaItemPropertyTitle], [mediaItem valueForProperty:MPMediaItemPropertyArtist], [mediaItem valueForProperty:MPMediaItemPropertyAssetURL]);
self.fileURL = …Run Code Online (Sandbox Code Playgroud) objective-c mpmediapickercontroller mpmediaitem uidocumentinteraction
iphone uinavigationcontroller ios uidocumentinteraction swift
在iOS Safari中单击“共享”按钮时(通过工具栏或长按链接),我希望我的应用程序显示为“在...中打开”选项(例如,“在新闻中打开” ”),以便我的应用(这是另一种网络浏览器)可以打开Safari共享的任何内容http://或https://URL。
我已经在苹果info.plist文件中注册了文档类型“ URL”(我相信这是正确的类型,如果此假设是错误的,请更正!),我CFBundleDocumentTypes可以从Apple的“注册应用程序支持的文件类型”文档中猜到,他们的技术问答以及与之相关的StackOverflow帖子1 2 3:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFiles</key>
<array>
<string>appIcon320</string>
<string>appIcon64</string>
</array>
<key>CFBundleTypeName</key>
<string>URL</string>
<key>CFBundleTypeRole</key>
<string>Editor</string> <!-- Note: I have also tried 'Viewer' -->
<key>LSHandlerRank</key>
<string>Owner</string> <!-- Note: I have also tried 'Default' -->
<key>LSItemContentTypes</key>
<array>
<string>public.url</string>
</array>
</dict>
</array>
Run Code Online (Sandbox Code Playgroud)
我也用以下代码编写了这个存根方法AppDelegate.swift(尽管我认为实际上与使我的应用程序显示为“打开方式...”选项的第一阶段的成功无关):
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {opening-in-app-getting-uiapplicationlaunchoptionsurlkey-from-launchoptions?rq=1
print("Received URL: \(url); from …Run Code Online (Sandbox Code Playgroud) 我的UIDocumentsInteractionController正在使用一个带有"iBooks"按钮的动作表,但是当我点击那个按钮时,它只是解散它并没有把我带到iBooks.这是我的代码:
NSString *filenamePath =[NSString stringWithFormat:@"temp.%@", [[file path] pathExtension]];
NSString *docDir = [DataCenter getDocumentsDirectoryPath];
NSString *fullPath = [docDir stringByAppendingPathComponent:filenamePath];
NSURL *url = [NSURL fileURLWithPath:fullPath];
UIDocumentInteractionController *c = [UIDocumentInteractionController interactionControllerWithURL:url];
BOOL success = [c presentOpenInMenuFromBarButtonItem:buttonBack animated:YES];
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?谢谢
我目前正在显示一个UIDocumentInteractionController,以便我的应用程序的用户可以在另一个应用程序中打开一个文件.控制器弹出并列出应用程序没有问题.但是,它还会显示Cloud应用程序,例如Dropbox(我假设它几乎与每个有效的文件类型相关联),这非常令人讨厌.无论如何,我可以指定控制器只显示我想要的应用程序?
我UIDocumentInteractionController用于在我的应用程序中打开文档.我使用下面的方法预览PDF文件: -
- (IBAction)previewDocument:(id)sender
{
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"pdf"];
// Initialize Document Interaction Controller
self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
// Configure Document Interaction Controller
[self.documentInteractionController setDelegate:self];
// Preview PDF
[self.documentInteractionController presentOptionsMenuFromRect:down.frame inView:self.view animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
我已经读过,我们也可以通过其他应用程序读取应用程序中的文件UIDocumentInteractionController.
在我的应用程序中,如何使用其他应用程序读取文件UIDocumentInteractionController?这一切是如何发生的?
我使用此代码将一些PDF数据保存到文件中,使用"打开方式"菜单将其发送到另一个应用程序,然后在完成后删除该文件:
- (void)openIn:(NSData *)fileData {
// save the PDF data to a temporary file
NSString *fileName = [NSString stringWithFormat:@"%@.pdf", self.name];
NSString *filePath = [NSString stringWithFormat:@"%@/Documents/%@", NSHomeDirectory(), fileName];
BOOL result = [fileData writeToFile:filePath atomically:TRUE];
if (result) {
NSURL *URL = [NSURL fileURLWithPath:filePath];
UIDocumentInteractionController *controller = [[UIDocumentInteractionController interactionControllerWithURL:URL] retain];
controller.delegate = self;
[controller presentOpenInMenuFromBarButtonItem:self.openInButton animated:TRUE];
}
}
- (void)documentInteractionControllerDidDismissOpenInMenu:(UIDocumentInteractionController *)controller {
// when the document interaction controller finishes, delete the temporary file
NSString *fileName = [NSString stringWithFormat:@"%@.pdf", self.name];
NSString *filePath = [NSString …Run Code Online (Sandbox Code Playgroud) 我的应用程序将PDF分享给另一个第三方应用程序的能力在iOS 11中已经破坏.它显示了共享表,但是当我选择在另一个(第三方)应用程序中打开它时,它只是取消共享表并且什么都不做.
我已经确认的事情:
UIActivityViewController.共享URL会产生相同的行为.共享原始数据允许您"创建PDF",然后共享该PDF确实有效(但用户体验很糟糕).有没有其他人经历过这个或有任何想法如何解决它?
以下是显示问题的示例应用程序的完整代码.我在一个新的"单一视图"应用程序中创建了它.故事板只有两个按钮连接到两个动作.
class ViewController: UIViewController {
var docController: UIDocumentInteractionController!
@IBAction func open(sender: UIButton) {
// self.docController.presentPreview(animated: true)
self.docController.presentOptionsMenu(from: sender.frame, in:self.view, animated:true)
}
@IBAction func check() {
print(self.docController)
}
override func viewDidLoad() {
super.viewDidLoad()
let url = Bundle.main.url(forResource: "OrderForm", withExtension: "pdf")!
self.docController = UIDocumentInteractionController(url: url)
self.docController.delegate = self
}
}
extension ViewController: UIDocumentInteractionControllerDelegate {
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
func documentInteractionController(_ controller: UIDocumentInteractionController, willBeginSendingToApplication application: String?) …Run Code Online (Sandbox Code Playgroud) ios ×8
objective-c ×3
iphone ×2
swift ×2
xamarin.ios ×2
c# ×1
cocoa-touch ×1
filesystems ×1
ios11 ×1
mpmediaitem ×1
nsdata ×1
uidocument ×1
uikit ×1
uti ×1