拖拽文件到dock上面的icon來打開需要兩個操作:
1、代碼
在AppDelegate.m裏面添加delegate函數:
- (void)application:(NSApplication *)theApplication openFiles:(NSArray *)filenames
這個函數會自動被調用。
2、Info.plist
向Info.plist裏面添加代碼:
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeExtensions</key>
<array>
<string>*</string>
</array>
<key>CFBundleTypeName</key>
<string>Folder</string>
<key>CFBundleTypeOSTypes</key>
<array>
<string>****</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSTypeIsPackage</key>
<false/>
</dict>
</array>
一開始我只添加了代碼部分,結果不行,最後又添加了Info.plist部分,感覺蘋果應該讓步驟更簡單點,添加代碼部分就可以了,爲何還要添加Info.plist部分。