Obj-C:application:openFiles:(多个文件被丢弃)没有收到所有文件。漏洞?

Obj-C: application:openFiles: (multiple files dropped) not receiving all files. Bug?

我找到的最接近的是: 但是一直没有人回答。

我的问题是, 假设我在我的停靠应用程序中放置了 4 个文件:


如果我去调试我的程序,它会显示:

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 配置有误?

希望有人能帮帮我,先谢谢大家了!

像这样在info.plist中设置

<key>CFBundleDocumentTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeExtensions</key>
            <array>
                <string>*</string>
            </array>
            <key>CFBundleTypeName</key>
            <string>Files</string>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>LSItemContentTypes</key>
            <array>
                <string>public.data</string>
            </array>
        </dict>
    </array>

并在AppDelegate.m

中使用此方法
-(void)application:(NSApplication *)sender openFiles:(NSArray *)fileList{
 // use fileList array 
}

-(BOOL)application:(NSApplication *)sender openFile:(NSString *)filename{
    return YES;
}

我遇到了同样的问题,下面是我如何解决的:

@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
}