Skip to content

Commit

Permalink
Fix application badge removal
Browse files Browse the repository at this point in the history
  • Loading branch information
vtourraine committed May 29, 2013
1 parent 4ee367b commit 478e274
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 4 additions & 2 deletions client-ios/MyTee/Classes/MTEMyTeeAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ - (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
}
if ([entity.name isEqualToString:@"MTEWear"] || [entity.name isEqualToString:@"MTEWash"])
{
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
NSDateFormatter *formatter = [NSDateFormatter new];
formatter.dateFormat = @"yyyy-MM-dd";
if ([representation[@"date"] isKindOfClass:[NSString class]])
mutablePropertyValues[@"date"] = [formatter dateFromString:representation[@"date"]];
Expand All @@ -108,7 +108,9 @@ - (NSDictionary *)representationsForRelationshipsFromRepresentation:(NSDictionar
ofEntity:(NSEntityDescription *)entity
fromResponse:(NSHTTPURLResponse *)response
{
NSMutableDictionary *mutableRepresentations = [[super representationsForRelationshipsFromRepresentation:representation ofEntity:entity fromResponse:response] mutableCopy];
NSMutableDictionary *mutableRepresentations = [[super representationsForRelationshipsFromRepresentation:representation
ofEntity:entity
fromResponse:response] mutableCopy];

if ([entity.name isEqualToString:@"MTETShirt"])
{
Expand Down
16 changes: 16 additions & 0 deletions client-ios/MyTee/Classes/MTETShirtExplorer.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ @interface MTETShirtExplorer () <NSFetchedResultsControllerDelegate>
@property (strong, nonatomic) NSFetchedResultsController *fetchedResultsController;

- (void)filterFetchedObjects;
- (void)clearBadgeIfNecessary;

@end

Expand Down Expand Up @@ -81,9 +82,24 @@ - (void)filterFetchedObjects
else
self.fetchedTShirts = self.fetchedResultsController.fetchedObjects;

[self clearBadgeIfNecessary];

return;
}

- (void)clearBadgeIfNecessary
{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"MTEWear"];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit)
fromDate:[NSDate date]];
NSDate *thisMorning = [calendar dateFromComponents:components];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"date > %@", thisMorning];
NSUInteger countOfWearToday = [self.fetchedResultsController.managedObjectContext countForFetchRequest:fetchRequest error:nil];
if (countOfWearToday > 0)
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
}

- (NSUInteger)numberOfTShirts
{
return [self.fetchedTShirts count];
Expand Down
6 changes: 3 additions & 3 deletions client-ios/MyTee/Classes/MTETShirtViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@ @implementation MTETShirtViewController

- (void)setTshirt:(MTETShirt *)newTShirt
{
if (_tshirt != newTShirt) {
if (_tshirt != newTShirt)
{
_tshirt = newTShirt;

// Update the view.
[self configureView];
}

if (self.masterPopoverController != nil) {
if (self.masterPopoverController != nil)
[self.masterPopoverController dismissPopoverAnimated:YES];
}
}

- (void)configureView
Expand Down

0 comments on commit 478e274

Please sign in to comment.