ALAlertBanner icon indicating copy to clipboard operation
ALAlertBanner copied to clipboard

Banners get stuck if Application goes to background whilst they are appearing

Open jamesrgrinter opened this issue 11 years ago • 6 comments

This seems to be a similar issue to if the view Disappears, but the workaround for that (calling forceHideAllAlertBannersInView:) doesn't seem to do the job here.

To reproduce: perform an action that causes some banners to appear in your app, then put the app to background (i.e. press the Home button) whilst the banners are still appearing. (That they are still appearing/queued to appear seems to be key to reproducing.)

I have tried subscribing to UIApplicationDidEnterBackgroundNotification, to call forceHideAllAlertBannersInView. But when returning to the app I usually see at least one Banner appear and others remain - no longer able to dismiss them with a tap. At this point, no further banners will ever appear - calling forceHideAllAlertBannersInView: from viewWillDisappear: will not reset the situation.

jamesrgrinter avatar Sep 20 '14 19:09 jamesrgrinter

I have the same issue. any solution ?

isayeter avatar Sep 25 '14 22:09 isayeter

I have a temporary solution until fixing completely.

I added these lines before showing banner,

UIApplication *application = [UIApplication sharedApplication];
UIApplicationState appCurrentState = [application applicationState];
if(appCurrentState == UIApplicationStateActive)
{
    //create and show ALAlertBanner
}

isayeter avatar Sep 25 '14 22:09 isayeter

I've gone for re-initialising all three semaphores in the forceHideAllAlertBannersInView: method, so that they're in a known "good" state.

jamesrgrinter avatar Sep 26 '14 09:09 jamesrgrinter

can you share your solution ?

isayeter avatar Sep 26 '14 11:09 isayeter

https://github.com/jamesrgrinter/ALAlertBanner/commit/2c3e3b36aa88fba81bcfbb47fcdbdbc8196669ab is my fix to ALAlertBanner - though I'm not saying that this is the right fix, it's actually a bit of a sledgehammer approach that it resets the semaphores that are used to prevent more than one animation at a time.

My own app code then calls forceHideAllAlertBannersInView: from viewWillDisappear: in whichever views they're shown, but also adds an observer for UIApplicationDidEnterBackgroundNotification in those views so that it can invoke the method when the app enters the background.

jamesrgrinter avatar Sep 26 '14 19:09 jamesrgrinter

@jamesrgrinterThank you I've been struggling with this! When the app enters background though the managers still gets confused even with the observer. Or am I doing it wrong?

StefanICT avatar Oct 02 '14 14:10 StefanICT