-4

I want to know how to use a condition saying

if(appHasNewlyLaunced)
{
// read a file 
}
else
{
// read another file.
}

Is there any inbuilt class or property to check this. I am new to iOS so it could be a simple one , but I have no idea.

Thanks

  • Can you expand on "newly launched"? Do you mean you want to know when the app launches, or you want to know when the app launches for the first time ever? – Caleb Sep 16 '13 at 05:56
  • you want to know that your application launch first time or not ?? – iPatel Sep 16 '13 at 05:56
  • http://stackoverflow.com/questions/1664177/best-way-to-check-if-an-iphone-app-is-running-for-the-first-time and http://stackoverflow.com/questions/11237008/how-to-determine-that-user-runs-the-app-for-the-first-time – iPatel Sep 16 '13 at 05:57
  • no i just want to know when the app. launches. I am not bothered about its first time launch. But your idea will be helpful for my learning. – Ashish Priyadarshi Sep 16 '13 at 05:57
  • **Close voters:** read the question and comments -- the OP is **not** asking how to detect the *first* time the app launches, but rather needs to perform an action *whenever* the app launches. Simple question, yes, but nevertheless different from the suggested dupes. – Caleb Sep 16 '13 at 06:40

1 Answers1

0

i just want to know when the app. launches

There's a method in the app delegate that's called when the app launches. It's called -application:didFinishLaunchingWithOptions:. You need to implement that method in your app delegate, and you can add whatever code you want to execute when the app launches.

I am new to iOS

Take some time to learn what's expected of an iOS app before you dive in. If you invest some time up front, it'll pay for itself many times over. For example, you probably didn't know that applications are expected to provide an object to act as the application's delegate, else you would have looked at the UIApplicationDelegate protocol before asking your question.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • i completely agree what you said. Its my third day and got an urgent bug fix.. so have to jump in.. I checked out app delegate. but i cannot use the mentioned method . Let me make it more descriptive. I have to set some text boxes to "" when the app. launches but i have created the textboxes is another class than app delegate. so those text fields cannot be accessed in app delegate method. so i am looking for some sort of condition. – Ashish Priyadarshi Sep 16 '13 at 06:33
  • @AshishPriyadarshi You can use the method described above to set some state in your app when the app launches, like `shouldClearTextFields = YES`. The view controller that manages the text fields in question should then check this state when it loads its view (see `-viewDidLoad` and also `-viewWillAppear`), and clear the values if necessary. – Caleb Sep 16 '13 at 06:38