5

I am using Local notification in my application.it is working fine in foreground and background.

Now, What i need,if i remove my app from background then i want to cancel all notification before that.

so , there are not any method are calling in appdelegate when i am going to remove my app from background, obviously it is going to Suspended state so no method is going to called.

so is there any other way to do this ?

Thanks in advance...

PJR
  • 13,052
  • 13
  • 64
  • 104
  • i don't think this is possible..app delegate `appWillTerminate` is most times not called when app is killed from suspended state – Shubhank Dec 14 '12 at 06:10
  • thanks @Shubhank , i had idea about it , but is there any other way ?because my app is automatically logout when i removed it from background , so i have to cancel notification. – PJR Dec 14 '12 at 06:11
  • yes means ,every time i open my app after removing it from background , it is asking new username and password, – PJR Dec 14 '12 at 06:16
  • you can code it to remember username and password ! – Shubhank Dec 14 '12 at 06:18
  • yes , i know it is possible but it is against requirement.thats why i am searching for other option. – PJR Dec 14 '12 at 06:19
  • That's tricky, but for me you should remove them and logout when your app goes in BKG. You can't know when or if your app is freezed in a suspended state in BKG, because is managed by the system. If after using your app I play DeadSpace I'm pretty sure that your app will be killed and there are no messages sent to it. How can you automatically logout your app? do you have an active socket? – Andrea Dec 14 '12 at 07:55
  • @Andrea no i have not any socket ? actually i do not logout but every time asking for username password , so user have to login again,and i need notification in background so i can not stop them in BKG – PJR Dec 14 '12 at 08:40
  • Well for me there is something wrong in the flow. The fact is that you can't be notified if your app it has been killing. Actually you don't do a real logout, but if your app is killed and awaken by a local notif you can of course ask again for credentials. The other way around is pass the credential to the local notification using the userInfo dictionary, and in this way you are not required to ask again user for credential but you just pass to your login class. – Andrea Dec 14 '12 at 09:17

1 Answers1

0

Considering your app is not one of the supported background execution modes, like audio, VoIP, or navigation, Your app will generally never see willTerminate, because the system generally only terminates your app once it's already suspended (in the background). Once your app is suspended, it gets no further chance to act, so there's no callback for that.

The didEnterBackground delegate message or notification should be considered your last chance to clean things up or save state before possible termination.

Here and here are good overview of the application lifecycle notifications & delegate messages on iOS 4.0 and later.

Suresh Varma
  • 9,750
  • 1
  • 60
  • 91
  • if i set 'updatelocation' on then will it call?or it is not a good idea and apple is going to reject it because i am not using location in my app. – PJR Dec 14 '12 at 07:27
  • In this case if user turns off his location Services then your app will break... Check out the [link](http://stackoverflow.com/questions/3762200/how-to-keep-an-iphone-app-running-on-background-fully-operational) to get some help in running app in BG – Suresh Varma Dec 14 '12 at 07:33