objective-c - Obj-C : application:openFiles: (multiple files dropped) not receiving all files. 错误?

标签 objective-c cocoa drag-and-drop info.plist

我找到的最接近的是:https://stackoverflow.com/questions/4778932/cocoa-app-not-receiving-all-dropped-files-in-applicationopenfiles 但尚未得到答复。

我的问题是这样的, 假设我要在 Dock 应用程序上放置 4 个文件:

  • 测试.xls
  • 测试.rtf
  • 测试.jpg
  • 测试.pdf


如果我去调试我的程序,它会显示以下内容:

Debug log

如您所见,.jpg 文件不在那里。 这也会发生在:.py、其他图像类型、.txt 文件 我发现,如果我仅从该组(.py .jpg .txt)中删除文件,那么它会识别所有这些文件。

我的 Info.plist 看起来像这样:

<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPEplistPUBLIC"-//Apple//DTDPLIST1.0//EN""http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plistversion="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeName</key>
<string>AllFiles</string>
<key>CFBundleTypeIconFile</key>
<string>application.icns</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSHandlerRank</key>
<string>Alternate</string>
<key>LSItemContentTypes</key>
<array>
<string>public.item</string>
</array>
</dict>
</array>

我不知道错误出在哪里,也许这是一个错误?或者我的 info.plist 配置错误?

我希望有人能帮助我,提前谢谢大家!

最佳答案

我遇到了同样的问题,解决方法如下:

@property (strong) NSMutableArray *openFilesList;
@property (strong) NSTimer *openFilesTimer;

...

@synthesize openFilesList;
@synthesize openFilesTimer;

...

-(void)init {
    openFilesList = [[NSMutableArray alloc] init];
    openFilesTimer = nil;
}

-(void)application:(NSApplication *)sender openFiles:(NSArray *)filenames {
    if (openFilesTimer) {
        [openFilesTimer invalidate];
    }
    [openFilesList addObjectsFromArray:filenames];
    openFilesTimer = [NSTimer scheduledTimerWithTimeInterval:0.2f
                                                      target:self
                                                    selector:@selector(processOpenFiles)
                                                    userInfo:nil
                                                     repeats:NO];
}

-(void)processOpenFiles {
    NSArray *filenames = [openFilesList copy];
    openFilesTimer = nil;
    [openFilesList removeAllObjects];

    // Do your processing with filenames
}

关于objective-c - Obj-C : application:openFiles: (multiple files dropped) not receiving all files. 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34039173/

相关文章:

objective-c - 要创建一个空字典,[NSMutableDictionary dictionary] 或 [[NSMutableDictionary alloc] init]?

javascript - 悬停子元素时触发 HTML5 dragleave

jquery - 在 mobilesafari 中重新排序项目

ios - 图片的异步下载

objective-c - UIScrollView subview 中的 UITapGestureRecognizer

cocoa - 变换后CALayer与顶层重叠

xcode - 从自定义 View 内的 NSButton 隐藏 NSMenu

c# - 如何将项目从一个列表框拖放到另一个列表框

iphone - 在 iOS 5 中使用 MPMoviePlayerController 重复视频中的场景的最佳方式?

ios - 计算每个应用程序的蜂窝数据使用量