0

I am using cordova 2.1.0 for my IOS app development. I connected my IOS device to a MAC processor and installed/initialized my app running in xcode or dragged it from itunes folder. Now i physically disconnected my device from the processor and through wifi enabled in the device, sent notifications/messages through APNS to the device. I was able to successfully receive notifications in the device. Now after some time, i reconnected the device to the processor, which lead to a problem of the app launching again and calling 'didFinishLaunchingWithOptions' method again, which is not desirable as the launch/initialization should happen only once. This behaviour is random ie. every time when i disconnect/reconnect, it is not happening, only sometimes. Why is this happening. What could be the reason for this random behaviour.

Any help will be appreciated.Thanks

clint
  • 1,786
  • 4
  • 34
  • 60
  • You should read the iOS programming guide by apple and truly understand the lifecycle of an app. – Eiko Oct 10 '12 at 13:59

1 Answers1

1

didFinishLaunchingWithOptions: is called every time the app is launched. When you run your app from Xcode, and disconnect the device, it kills the app. So, when you launch the app with the device disconnected, it starts the app again, which calls didFinishLaunchingWithOptions: when the app finishes launching. The same thing happens if you run the app from Xcode, and run it again the same way.

EDIT :

Not sure if it's clear, but didFinishLaunchingWithOptions: is not called if you quit the app (press the home button) and call it back without killing it.

rdurand
  • 7,342
  • 3
  • 39
  • 72
  • So as per you, even if i connect the device for charging, it should call 'didFinishLaunchingWithOptions' function again and launch the app again. – clint Oct 10 '12 at 10:13
  • If your run in Xcode, disconnect, reconnect (or not) and launch the app from your device (touch the icon on the springboard), it calls. If you run in Xcode, disconnect, reconnect and run in Xcode, it calls. Basically, as I said, it's called every time the app is *"launched"*. The app is "launched" when it was previously terminated. It is terminated when you were running from Xcode and you disconnect the device, when you quit the app and kill it manually in the multitasking bar, when you reboot, or if the device runs out of memory. I hope it's more clear now, is it ? – rdurand Oct 10 '12 at 11:07
  • i have got some what, see running in xcode is only for me as a developer. At the end of the day, for an end user it has to be downloaded from itunes or dragged from itunes folder in MAC machine(with device connected). So, in these two scenarios, it should not launch again. Otherwise, its not serving the purpose. How can i make sure that in these scenarios, it never launches again. – clint Oct 10 '12 at 12:13
  • The user is going to install it via iTunes, and it will appear on his springboard. When he launches for the first time, didFinishLaunchingWithOptions: will be called. When he's done with the app, he will exit it (click the home button). If he goes back to the app a few moments later, it won't be called. But if he stops using it for a longer time (say a week, for example) the app will most likely be killed by the OS. When he launches it again, didFinishLaunchingWithOptions: will get called again. That's not a bug, it's how apps run. [No space left, new comment] – rdurand Oct 10 '12 at 12:18
  • If you want something to happen only at first launch, look over there : http://stackoverflow.com/questions/308832/iphone-the-quickest-and-easiest-way-to-detect-first-launch – rdurand Oct 10 '12 at 12:19