0

I've got sort of a problem with my ios application. It handles the Apple Push Notification (APN) and everything BUT, my app handle it in it appDelegate.m

The problem is I want to make a button to change color if the user have a notification, so I search a way to do it and I found "Run Loop", is this possible to have a Run Loop in a secondary thread to check infinitely if there is a new notification? (with a wait of 5/10 seconds between each verification) I don't really know how to declare it neither to make it works alone. (I'm pretty new with xCode and used the AFNetworking asynchronous methods for the rest of the app so I'm not really good with threading and co.)

It could be really great if someone is able to give me a way to implement a simple run loop in my app.

Thank you!

EDIT : I have a white button for User profile, and I want it to change to Red when the user have a notification, the button is already declared and works in a viewController, but I don't manage to link it to the appDelegate, that's why I'm asking to do a RunLoop who could handle a BOOL sent by the appDelegate, that my view do only in the viewDidLoad (that don't really work when app is in background etc...)

Jeromiin
  • 71
  • 7
  • "I want to make a button to change color if the user have a notification"? You want to add a button when the notification occurs so the user can change color (of something)? It's not clear what you want. – trojanfoe Aug 21 '14 at 08:32

1 Answers1

1

I don't really see why you need a Run loop?

You could use NSNotificationCenter. https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/nsnotificationcenter_Class/Reference/Reference.html

AppDelegate.m

-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{

    if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"didRecieveNotification" object:nil userInfo:userInfo];
    }

}

And add your ViewController where the button lives as a observer:

- (void)viewDidLoad {
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNotification:) name:@"didRecieveNotification" object:nil];
}

-(void)handleNotification:(NSNotification *)notification
{
    YourButton.backgroundColor = [UIColor redColor];
}
bangerang
  • 473
  • 1
  • 6
  • 15