Reputation: 389
I have a situation where I need to constantly poll the cloud and see if there is data available or not and then inform the user(App) with an updated navigation item's leftbar buttons with updated icons.
So the flow is like this: In the Appdelegate, I have an NStimer object that fires every 1 minute to load metadata from the cloud. Once the metadata is loaded, it notifies that the data load was successful. That notification is observed by whichever view controller is visible in the ViewController stack.
So, questions: a) Is this pattern sustainable and scalable? I want to be cloud agnostic here. b) what can be done to refine this strategy to make it scalable? c) What are the alternate strategies available to accomplish this?
i will post the code if anyone is interested in the problem further.
Upvotes: 0
Views: 332
Reputation: 3718
I'll give you the code snippet for updating the left button. Obviously you can change around various variables in here, so take this as an example.
-(void) configureLeftBarButtonItem
{
UIButton * leftButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 11.5, 15)];
[leftButton setBackgroundImage:[UIImage imageNamed:@"backarrow.png"] forState:UIControlStateNormal];
[leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
// you can obviously do any image name and any selector and any view, button is just a classic example
UIBarButtonItem *leftButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
// this is so that the button is not right up against the side
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = 10;
self.navigationItem.hidesBackButton = YES;
self.navigationItem.leftBarButtonItems = [NSArray
arrayWithObjects:negativeSpacer, leftButtonItem, nil];
}
In terms of scalability, I'm not an expert in this area, but I have written a few server driven applications and I think requesting a server once a minute is not that taxing on a given server and basically reasonable. I have requested servers every 10-15 seconds (quasi messaging app) and it was fine. I do think updating a navigation item every minute randomly from a server might not make for the best User Experience, as I can imagine the constantly changing navigation flow would possibly be confusing to users. That being said, I am not sure what your specific needs are, so I can't comment that much further.
Upvotes: 1