Detect first time app has run

5 views
Skip to first unread message

Dan Grigsby

unread,
Feb 27, 2009, 11:24:59 AM2/27/09
to iphon...@googlegroups.com
I'd like to display my info screen the first time my app is run. I'm
planning on doing this by looking for the presence of a file; if it's
not there I'll show the info screen (and create it) else I'll load the
default screen. Is there a better way to do this? Google didn't turn
anything up.


---

Mobile Orchard: The iPhone Development Blog
News and views for iPhone™ & iPod Touch™ App Developers
www.mobileorchard.com

Damon Allison

unread,
Feb 27, 2009, 11:31:36 AM2/27/09
to iphon...@googlegroups.com
You could store a flag in NSUserDefaults, set to true when shown.

checking to see if the flag was set:

BOOL warningShown = [[NSUserDefaults standardUserDefaults] boolForKey: @"BLWarning"];


setting flag

  [[NSUserDefaults standardUserDefaults] setBool: YES forKey: @"BLWarning"];
  [[NSUserDefaults standardUserDefaults] synchronize];

Neil Mix

unread,
Feb 27, 2009, 12:52:02 PM2/27/09
to iphon...@googlegroups.com
On thing to be aware of is that defaults information is wiped out on
upgrade or uninstall/re-install. If that's not ideal, I believe you
can write files to the documents directory which isn't wiped out on
upgrade. You'd use NSFileManager class for that.
--
My info:
Work: http://www.pandora.com/
Play: http://www.neilmix.com/

Martin Grider

unread,
Feb 27, 2009, 1:47:55 PM2/27/09
to iphon...@googlegroups.com
Wait a sec... NSUserDefaults information is deleted on upgrade?!? Is
this true? My understanding was that NSUserDefaults was the preferred
method of storing user data... over filesystem. My app stores pretty
much everything in there. If this is true, I've got some re-writing to
do.

Neil Mix

unread,
Feb 27, 2009, 2:48:00 PM2/27/09
to iphon...@googlegroups.com
Yeah, so this bugger is a bit tough to unwind. The defaults system is
based on the Preferences system, and the "The Preferences System"
documentation begins with a disclaimer "Important: The assumption with
user preferences is that they are not critical; if they are lost, the
application should be able to recreate the default set of
preferences." And while it's not documented anywhere that I've found,
they are definitely wiped out on upgrade.

The "File and Data Management" documentation gives a great description
of the filesystem, what's on/off limits, and what gets backed up.

Martin Grider

unread,
Feb 27, 2009, 2:57:47 PM2/27/09
to iphon...@googlegroups.com
Hmm. I got informal confirmation (via IRC) that NSUserDefaults are NOT
deleted on upgrade.

Dan Grigsby

unread,
Feb 27, 2009, 3:02:23 PM2/27/09
to iphon...@googlegroups.com
Damon,

Thanks. This is easier, and the limitations I can live with.

Best,

Dan

Neil Mix

unread,
Feb 27, 2009, 4:25:46 PM2/27/09
to iphon...@googlegroups.com
I can't speak to the experience of your anonymous IRC sources, but my
experience with 4 app upgrades says otherwise.

Martin Grider

unread,
Feb 28, 2009, 3:34:31 PM2/28/09
to iphon...@googlegroups.com
https://devforums.apple.com/message/36516#36516

Also seems to imply NSUserDefaults are not wiped.

Neil Mix

unread,
Feb 28, 2009, 4:59:54 PM2/28/09
to iphon...@googlegroups.com
Try it and let us know what you find out. I'll be happy if you prove me wrong.

Martin Grider

unread,
Apr 16, 2009, 7:57:32 PM4/16/09
to iphon...@googlegroups.com
Heya Neil and everyone.

I was fairly certain before I released my game, but today the first update has (finally) come out, and I can say definitively that NSUserDefaults are not wiped on application update. ...just FYI. Not sure why you thought that Neil, but it's pretty important to my game (for saving high scores and statistical data), and thankfully all of that stuff works just fine on update by all reports.

Also, if you haven't checked it out already, there is now a "Lite" (aka Free) version of ActionChess in the app store. You can get a feel for the game without paying $3 for the whole shebang. Unfortunately, NSUserDefautls are not shared between applications, (without doing some additional work to set up your own "domain"), so your high scores and such will not be saved when you update to the full version.   ;)

thanks,
-martin
http://chesstris.com/actionchess/

Neil Mix

unread,
Apr 17, 2009, 11:51:48 AM4/17/09
to iphon...@googlegroups.com
> I was fairly certain before I released my game, but today the first update
> has (finally) come out, and I can say definitively that NSUserDefaults are
> not wiped on application update. ...just FYI.

Glad to hear it Martin, sorry that my information was incorrect.
Thanks for letting us know. Definitely something to keep in mind for
future updates so that I don't have versioning conflicts in the
persistence. Would hate to have people upgrade to a nice big crash!

> Not sure why you thought that Neil,

Because I saw it happen with my own eyes. Not sure I can state it any
more clearly or definitively. Admittedly, this was within a month or
so after the initial AppStore launch, so there may have been an
explicit change in behavior of the app loader since then. Hopefully
it's that and not some sort of implicit code path or environmental
difference. Undocumented behavior can be treacherous...

Cheers,
-Neil

Paul Cantrell

unread,
Apr 19, 2009, 12:58:35 PM4/19/09
to iphon...@googlegroups.com
I think there may have been an early bug that caused this. I remember
a few of my early apps having their settings wiped when I upgraded —
and then it never happened again.

P
Reply all
Reply to author
Forward
0 new messages