change app delegate in different class

Discussion in 'iOS Programming' started by tiaan3365, Jan 8, 2013.

  1. tiaan3365 macrumors newbie

    Joined:
    Jan 8, 2013
    #1
    Good day all

    I would like to know if you can change a method in my app delegate on an event in another class.

    I basically want to add a local notification to the didenterbackground method on a time set on another form.

    I hope someone could help.
     
  2. KoolStar macrumors demi-god

    KoolStar

    Joined:
    Oct 16, 2006
    Location:
    Kentucky
    #2
    That method call is a response from UIApplication and thus only calls in the app delegate. If you want another class to react to the enter background you can have it register a selector on the notification center.

    Code:
    [[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(handleEnteredBackground:) 
                                                 name: UIApplicationDidEnterBackgroundNotification
                                               object: nil];
    
    Code:
    - (void)handleEnteredBackground:(NSNotification*)notification
    {
        //Your Logic
    }
    
    NOTE: Be sure to remove the observer from your class when it is dealloced or the view is removed from the hierarchy.

    The specific key is the :UIApplicationDidEnterBackgroundNotification

    These are all notifications you can register in other classes with notification center.

    Code:
    UIApplicationDidBecomeActiveNotification
    UIApplicationDidChangeStatusBarFrameNotification
    UIApplicationDidChangeStatusBarOrientationNotification
    UIApplicationDidEnterBackgroundNotification
    UIApplicationDidFinishLaunchingNotification
    UIApplicationDidReceiveMemoryWarningNotification
    UIApplicationProtectedDataDidBecomeAvailable
    ApplicationProtectedDataWillBecomeUnavailable
    UIApplicationSignificantTimeChangeNotification
    UIApplicationWillChangeStatusBarOrientationNotification
    UIApplicationWillChangeStatusBarFrameNotification
    UIApplicationWillResignActiveNotification
    
     

Share This Page