I want to be able to display an alert describing what's new when an app has been updated. What's the best way to do this, especially considering iOS 7 automatically updates apps? Thanks!
You can store the app version in NSUserDefaults. Then if the old app version != current app version you can display your dialog
Version #:
NSString * version = [[NSBundle mainBundle] objectForInfoDictionaryKey: #"CFBundleShortVersionString"];
Set:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:version forKey:#"appVersion"];
Get:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults objectForKey:#"appVersion"];
When the user starts your app, check a version string in user defaults or a file or database.
If you want to do it around the time the app is updated, you might be able to use push notifications in conjunction with the version check. I don't know whether you can get the new app to check the version in the background, though (never used push notifications myself).
Checkout my question I've made some weeks ago (NSUserDefaults behaviour with app update). I think can solve your problem.
The idea is to use NSUserDefaults to store the last version that your device have ever ran, and if a greater version than the one I've got stored in the NSUserDefault object is going to be run, then you do whatever you want to do, in this case displaying an alert describing what's new when the app has been updated.
Related
I'm writing a feature of the language change. First screen of the app I'm writing is about setting the language. When he user presses the button, my app directs user to app settings. I expect user to set some language and show it to them as soon as they go back to my app.
But as soon as I click on some language option, my app xcode console says:
Message from debugger: Terminated due to signal 9
Additionally, as soon as I return to my app, it gets loaded as if I closed and reopened it.
I thought that maybe I can have some code that will set a global variables like "currentLanguage" and "previousLanguage" and if those are different - I will load localisation files for "currentLanguage" and will start downloading localised videos from my server.
System terminate your app when user change language in Settings. So you can use NSUserDefaults for persistent storage and compare this values on app start, to detect if language was changed.
Example:
NSString *currentLanguage = [[NSLocale preferredLanguages] firstObject];
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject: currentLanguage forKey:#"previousLanguage"];
NSString *previousLanguage = [userDefaults objectForKey:"previousLanguage"];
This is how it is accomplished in my app:
I keep the data in iCloud.
I need to do some time consuming thing for users who already used my app. But this will also start for completely new users... they just downloaded my app from AppStore for the first time. And this is not expected.
How can I determine that the app is running, but downloaded from AppStore for the first time?
What I could do, but I did not:
put any boolean data in the Keychain, and then check if it exists.
Since you have no non-app end to distinguish users Keychain as you mentioned is your only app persistance option that will survive app uninstalling. Only device Reset to factory settings would remove it.
you can use NSUserDefaults . if appDelegate.m ->didFinishLaunchingWithOptions use this code :
NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
if([userDefaults objectForKey:#"first_time"] == nil){
[userDefaults setObject:#"1" forKey:#"first_time"];
//do whatever you need
}
this condition will satisfied only once after installation .
I have an ios app, and recently have been getting some reports from users about their settings getting reset.
The settings are saved using NSUserDefaults.
My question is, can the user defaults get corrupt/reset for some reason?
A few notes about how I use it:
When I start my app, I store default values only if the keys doesn't exist using registerDefaults (this is done to take care of the "first install" scenario).
Most of the aforementioned reports describe the app crashing, and then when it is reopened the settings are reset to default.
My usage of NSUserDefaults is pretty straightforward - saving numbers/strings, reading them sometimes, etc. Nothing too fancy. I don't remove keys.
Some code examples:
For example, I'm saving the data in different places using:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:#"FirstLevel" forKey:#"Level"];
[defaults setInteger:100 forKey:#"Score"];
[defaults synchronize];
I read using:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
int intValue = [defaults integerForKey:#"Score"];
return intValue;
So, can something cause the user defaults to get reset/corrupt somehow?
More generally, can it be related to the app crashing that was reported, even if the crash is not directly as a result of writing/reading from user defaults?
From what I understand, it is only swiped out when app is deleted. Since your NSUserDefaults' reset issue was preceding by the app crashed, I would start by figure out the crashing issue.
If you install your app in your device the NSUserDefault will be Re initialized again… when ever you test your app in device you will connect your device with Xcode and if you run the program the values will be reset…
I would like to implement certain activities like Display the Help / tutorials slide show, what is new slide show and download some files and database for the use by the app during the first run after installing the app on the device. Also make some language and other settings. Is there a method in iOS to do this are there some example or tutorials known to any of you who can share it for me.
You can use NSUserDefault to keep track of first launch.
Here is the sample code:
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
BOOL firstLaunch = [userDefaults boolForKey:<firstLaunchKey>];
if (firstLaunch) {
<present Help, tip etc.>
[userDefaults setBool:NO forKey:<firstLaunchKey>];
}
Some basic ios app tutorials:
http://www.creativebloq.com/app-design/how-build-app-tutorials-12121473
Database -> How is an iPhone database created for the first time?
Slideshow->
Three20: https://github.com/facebook/three20
and
Apple's UICatalog https://developer.apple.com/library/ios/#samplecode/UICatalog/Introduction/Intro.html
Some Simple code sample for iOS Content storage, sync, management:
http://quickblox.com/developers/SimpleSample-content-ios
When my application loads up, it acts as an installer. When you tap the "Install" button, the application does it's task. It installs what is needed, and then you can carry on throughout using the app. My app is working fine, but whenever I close out the app of the multitasking bar, the app loads like the original installer again. Thus, the user having to keep reinstalling every time the app is loaded again. I want the user to only have to install the items once, be able to close the app, then use the content again without having to re-download. I know that I will be needing to use NSUserDefaults for this, but I also want the "Install" button to permanently disappear along with the installer. NOTE THIS IS NOT A STORE. This is just a test app for installing content that I may use further down the road. How would I be able to do all of this? Any help is appreciated. Thanks!
Having implemented something like this a few times, it's best to detect first launch, and show the installer screen based on that. However, there are cases where the user doesn't quite finish installation, and the app is somehow backgrounder or killed. In which case, you need to store another variable that records whether the user has completed the install.
The simplest way is to present a modal view controller as a sort of wizard if setup isn't initially completed, and just load the main screen as usual if it is.
Just query user defaults before you install. If it comes up not installed, then install whatever is needed and then set the user defaults!
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *isInstalled = [defaults objectForKey:#"installed"];
if( ![isInstalled isEqualToString: #"true"] ) {
//do installation here
NSString *hasUserInstalled = #"true";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:hasUserInstalled forKey:#"installed"];
[defaults synchronize];
}