我找到的最接近的是:https://stackoverflow.com/questions/4778932/cocoa-app-not-receiving-all-dropped-files-in-applicationopenfiles 但尚未得到答复。
我的问题是这样的, 假设我要在 Dock 应用程序上放置 4 个文件:
- 测试.xls
- 测试.rtf
- 测试.jpg
- 测试.pdf
如果我去调试我的程序,它会显示以下内容:
如您所见,.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/