2012-05-30 47 views
2

我有一個提交給Apple Mac App Store的Qt應用程序。它已經拒絕寫入〜/庫/首選項/ com.mycompany.myappQt Mac App Store應用程序拒絕接收文件系統請求

這裏是我收到的消息:

2.30 

The application accesses the following location(s): 

'~/Library/Preferences/com.nourayn.AlMosaly.plist' 

The application may be 

* creating files 
* writing files 
* opening files for Read/Write access (instead of Read-Only access) 

in the above location(s). 

如何解決這一問題?

回答

5

我相信你正在使用QSettings保存應用程序設置。您的代碼可能看起來是這樣的:

QApplication app; 
app.setOrganizationDomain("nourayn.com"); 
app.setApplicationName("AlMosaly"); 
QSettings settings; // this creates a .plist file under ~/Library/Preferences 
        // which is non-MacAppStore-friendly 

相反,你可以明確指定的文件名創建QSettings:

app.setOrganizationDomain("nourayn.com"); 
app.setApplicationName("AlMosaly"); 
QSettings settings(yourAppDataFolder+"/settings.plist", QSettings::NativeFormat); 
        // this writes to the file you specified 

如果您在多個地方在你的應用程序中使用QSettings,這樣做可能會緩解東西一點點:

// in main.cpp 
app.setProperty("SettingsFileName", yourAppDataFolder+"/settings.plist"); 

// in someotherfile.cpp 
QString settingsFileName = qApp->property("SettingsFileName").toString(); 
QSettings settings(settingsFileName, QSettings::NativeFormat); 

此外,如果您在〜/庫/(存儲Qt的全局設置)一個com.trolltech.plist文件,你可能需要移動到的Qt 4.8.1。這裏更多的信息: http://qt-project.org/doc/qt-4.8/qsettings.html#changing-the-location-of-global-qt-settings-on-mac-os-x

+0

我在很多獨立的地方使用QSettings,我可以使用一個Api調用來設置設置位置,而不是在QSettings構造函數中設置每個QSettings對象我創造? –

+0

編輯我的答案來解決這個問題。你也可以檢查QSettings :: setPath()作爲@jdi建議,但我沒有嘗試過使用它。 – roop

1

蘋果開發者文檔解釋了在使用文件系統時允許的內容。您可以選擇使用API​​調用來處理它,否則您的位置和名稱數量有限。 Read in detail here

Your application may write to the following directories: 
~/Library/Application Support/<app-identifier> 
~/Library/<app-identifier> 
~/Library/Caches/<app-identifier> 

如果您使用的是QSettings,這將選擇系統的位置來存儲首選項,那麼你可能需要改變這種做法更加直接控制目標。

對於QSettings,瞭解如何將路徑更改爲優選位置的平臺/範圍的基礎上的文檔:http://qt-project.org/doc/qt-4.8/qsettings.html#setPath

QSettings::setPath(QSettings::IniFormat, QSettings::UserScope, 
        "/path/to/location"); 
+0

我知道這已經:) 我希望有一個簡單的方法來強制QSettings使用任意位置 –

+0

@AhmedSaid:本文檔介紹瞭如何設置路徑的平臺和範圍是:http:/ /qt-project.org/doc/qt-4.8/qsettings.html#setPath – jdi