1

Possible Duplicate:
Mac OS X: Where should I store save games for a game delivered as a bundle?

i am migrating my iOS game to mac. The file I used to store high scores is saved under xxx.app/Contents/Resources. However, when I enable the sandbox and entitlement, the directory becomes unwritable. I tried xxx.app and xxx.app/Contents as well without luck. so which directory should I use or which entitlement should I add?

EDIT I have tried ~/Library/Application Support/Your Game Name/ and it does not show permission errors but unable to save the game data. there is no Library under user/my_name, but one under unser/shared. Do i need to add any entitlements?

EDIT 2: Please dont close this question. The answer to earlier question does not work for me. Instead, the flagged answer of this question is correct.

Community
  • 1
  • 1
OMGPOP
  • 1,995
  • 8
  • 52
  • 95
  • You shouldn't be attempting to write to anywhere within your app bundle - I'm surprised you got away with this in the iOS version. – Paul R Jan 01 '13 at 10:16
  • @PaulR in iOS i write into the bundle directly. On mac, if i didn't enable the sandbox, it works as well. – OMGPOP Jan 01 '13 at 10:18
  • Just don't do it - you should never assume that your app will have write access to its bundle, for obvious reasons. – Paul R Jan 01 '13 at 10:20
  • @PaulR then which one should i use? Or can i add any entitlements for permissions? – OMGPOP Jan 01 '13 at 10:21
  • Put high scores in a writeable directory, such as Documents, or use your app's preferences. – Paul R Jan 01 '13 at 10:22
  • @PaulR I dont wanna store it in Documents since it is annoying for user and not safe if user deleted and don't know what it is. is there any designated place? what do you mean by app preferences – OMGPOP Jan 01 '13 at 10:26
  • @PaulR this is weird. I have tried ~/Library/Application Support/Your Game Name/ but failed. It does not prompt the permission error but the file is not saved – OMGPOP Jan 01 '13 at 11:01
  • @PaulR Hi, please dont close this question, the answer to the earlier question does not work for me, but the answer to this question is correct. – OMGPOP Jan 02 '13 at 03:22

1 Answers1

5

Under app sandboxing your app has a container folder in which it can write pretty much anywhere, however I would recommend just writing to the Data/Documents folder, which can be obtained using the following code:

NSString *documentDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

This will give you the folder at ~/Library/Containers/com.yourdomain.yourapp/Data/Documents. Note that the ~/Library folder is hidden under Lion/Mountain Lion so needs to be unhidden using this on the command line:

$ chflags nohidden ~/Library

(Only you, the developer, needs to unhide that folder so you can poke around from Finder to see what your app has written; your user's won't need to unhide it to use your app).

trojanfoe
  • 120,358
  • 21
  • 212
  • 242