Question

I have an iOS app that shows the user a set of different news feeds in a PageViewController. Everytime the app starts, it requests the news data from the backend for every single feed. In case it worked fine, a notification via for every single news feed is sent via NSNotificationCenter so the data can be displayed. In case of an error, a notification for every single feed is sent as well, triggering a popup message that tells the user something went wrong. But if this happens, a popup will be shown for every news feed, up to the amount of added news feeds.

My question is, how can I combine all those error case notifications to a single one and therefore avoid having many useless and annyoing popups?

Was it helpful?

Solution

if (self.isShowingErrorDialog) {
    return;  // Or possibly cache to show after current one is dismissed.
} else {
    [[UIAlertView ...] show];
    self.showingErrorDialog = YES;
}

OTHER TIPS

When you send a notification using NSNotificationCentre, you can include user info. This is basically an NSDictionary with additional information.

Why not just include the timestamp of the failed request. You can test this with some fuzziness to see if you've already put up an alert for this batch of requests.

- (void) notificationListener: (NSNotification*) notification {

    static NSDate* lastAlerted = nil;
    NSDate* sentDate = notification.userInfo[@"RequestDate"];

    if ( lastAlerted != nil && [lastAlerted timeIntervalSince:sentDate] > FUZZY_INTERVAL) {
        // post alert

        // And update last Alerted
        lastAlerted = sentDate;
    }

}

The method you need is postNotificationWithName:Object:UserInfo:.

Gordon

I don't think you can.

Just to confirm, the notifications you're sending are Apple remote notifications and the alerts are the system alerts popped up by the message centre.

The alerts occur before you get control, as the user has to have the opportunity to ignore them, or else people would use this as a cheat to make apps run in the background and kill user's batteries.

All you can do is send a batch token in your request, and check on the back end.

Good luck

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top