iosobjective-ccrashdeallocuialertviewdelegate

Access all UIAlertView object as a global object to control it Universally(to resolve CRASH in alert after deallocating the view contoller)


My requirement is to make my app's third tab as the home screen,and also whenever the user moves the app in background and while again moving the app to foreground it should be the home screen as our third tab instead the app is in any of the places in the app. This issue is handled(making third tab as home screen instead the app is in any of the places/scenarios in the app).,But i have an issue now which is generated by this resolution.

Problem :- If any alert is displaying in any view and we are making the app background-foreground ,the app comes to the third tab from that screen,and the alert is still there and if we click on the alert button ,then as per the rules of IOS the "self" object of the screen of alert is deallocated(because now we are in the home screen and the alert is here) and app CRASHES !

Tried some resolutions :-

1.In a screen ,I made an global object of UIAlertView and using below line of code in applicationDidBecomeActive method of the Screen...

[_alertToRemoveContact dismissWithClickedButtonIndex:1 animated:NO];

This is working code for this view,but my problem with resolution is that i need to create a global object of alert view in all places of the app which is a very much time consuming task because i am using around 250 alerts in the project.

2.I am killing the app whenever it moves to background ,In this resolution the problem is that my app will not work its downloading functionality in background cause the app is killed.

Need help for the resolution of this issue if any one need more explanations,please leave comments.

My Crash Log.... * -[ContactShowViewController respondsToSelector:]: message sent to deallocated instance 0x1138c4e0*

*Where ContactShowViewController will differ a/c to the screen Thanks in advance !!!


Solution

  • I have resolved this issue with the help of below solution :-

    1.I created an app delegate instance of UIAlertView.

    2.I implemented an alert view delegate method "will present alert view...",this method gives me all the alert view objects as a parameter where i have assigned it to my app delegate object of alert view.

    3.On application life cycle method "applicationDidEnterBackground" i am using below code ...,which resigns my alert dailog on coming from background to foreground...

    if ([AppDelegate shared].alertObserver) {

      //Dismissing alert which was shown before moving to background
    
        [[AppDelegate shared].alertObserver dismissWithClickedButtonIndex:0 animated:NO];
        [AppDelegate shared].alertObserver=nil;
    }