Skip to content

Commit

Permalink
[GH-ISSUE-118] Fix isSilentPush check
Browse files Browse the repository at this point in the history
  • Loading branch information
rlepinski committed Nov 29, 2016
1 parent ebf6d9b commit 55d71b1
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 14 deletions.
24 changes: 18 additions & 6 deletions AirshipKit/AirshipKit/UAUtils.m
Expand Up @@ -280,18 +280,30 @@ + (UIViewController *)topController {
}

+ (BOOL)isSilentPush:(NSDictionary *)notification {
BOOL isSilentPush = NO;
NSDictionary *apsDict = [notification objectForKey:@"aps"];
if (apsDict) {
id alert = [apsDict objectForKey:@"alert"];
NSString *badgeNumber = [apsDict objectForKey:@"badge"];
id badgeNumber = [apsDict objectForKey:@"badge"];
NSString *soundName = [apsDict objectForKey:@"sound"];

if (!alert && !badgeNumber && !soundName) {
isSilentPush = YES;
if (badgeNumber || soundName.length) {
return NO;
}

id alert = [apsDict objectForKey:@"alert"];
if ([alert isKindOfClass:[NSDictionary class]]) {
if ([alert[@"body"] length]) {
return NO;
}

if ([alert[@"loc-key"] length]) {
return NO;
}
} else if ([alert isKindOfClass:[NSString class]] && [alert length]) {
return NO;
}
}
return isSilentPush;

return YES;
}

@end
6 changes: 3 additions & 3 deletions AirshipKit/AirshipKitTests/UAAppIntegrationTest.m
Expand Up @@ -1060,7 +1060,7 @@ - (void)testPushActionsRunsInboxAction {
expectedActionPayload[kUADisplayInboxActionDefaultRegistryAlias] = @"message_id";

[[self.mockedActionRunner expect] runActionsWithActionValues:expectedActionPayload
situation:UASituationLaunchedFromPush
situation:UASituationBackgroundPush
metadata:OCMOCK_ANY
completionHandler:OCMOCK_ANY];

Expand All @@ -1084,13 +1084,13 @@ - (void)testPushActionsRunsInboxAction {
- (void)testPushActionsInboxActionAlreadyDefined {

// Notification with a message ID and a Overlay Inbox Message Action
NSDictionary *richPushNotification = @{@"_uamid": @"message_id", @"^mco": @"MESSAGE_ID"};
NSDictionary *richPushNotification = @{@"_uamid": @"message_id", @"^mco": @"MESSAGE_ID",};

// Expected actions payload
NSMutableDictionary *expectedActionPayload = [NSMutableDictionary dictionaryWithDictionary:richPushNotification];

[[self.mockedActionRunner expect] runActionsWithActionValues:expectedActionPayload
situation:UASituationLaunchedFromPush
situation:UASituationBackgroundPush
metadata:OCMOCK_ANY
completionHandler:OCMOCK_ANY];

Expand Down
58 changes: 53 additions & 5 deletions AirshipKit/AirshipKitTests/UAUtilsTest.m
Expand Up @@ -83,7 +83,33 @@ - (void)testIsSilentPush {
}
};

XCTAssertTrue([UAUtils isSilentPush:emptyNotification], @"Should be a silent push");
NSDictionary *emptyAlert = @{
@"aps": @{
@"alert": @""
}
};

NSDictionary *emptyLocKey = @{
@"aps": @{
@"alert": @{
@"loc-key": @""
}
}
};

NSDictionary *emptyBody = @{
@"aps": @{
@"alert": @{
@"body": @""
}
}
};
XCTAssertTrue([UAUtils isSilentPush:emptyNotification]);
XCTAssertTrue([UAUtils isSilentPush:emptyAlert]);
XCTAssertTrue([UAUtils isSilentPush:emptyLocKey]);
XCTAssertTrue([UAUtils isSilentPush:emptyBody]);


}

/**
Expand Down Expand Up @@ -117,10 +143,32 @@ - (void)testIsSilentPushNo {
}
};

XCTAssertFalse([UAUtils isSilentPush:alertNotification], @"Should not be a silent push");
XCTAssertFalse([UAUtils isSilentPush:badgeNotification],@"Should not be a silent push");
XCTAssertFalse([UAUtils isSilentPush:soundNotification],@"Should not be a silent push");
XCTAssertFalse([UAUtils isSilentPush:notification],@"Should not be a silent push");
NSDictionary *locKeyNotification = @{
@"aps": @{
@"alert": @{
@"loc-key": @"cool"
}
}
};

NSDictionary *bodyNotification = @{
@"aps": @{
@"alert": @{
@"body": @"cool"
}
}
};


XCTAssertFalse([UAUtils isSilentPush:alertNotification]);
XCTAssertFalse([UAUtils isSilentPush:badgeNotification]);
XCTAssertFalse([UAUtils isSilentPush:soundNotification]);
XCTAssertFalse([UAUtils isSilentPush:notification]);
XCTAssertFalse([UAUtils isSilentPush:locKeyNotification]);
XCTAssertFalse([UAUtils isSilentPush:bodyNotification]);
}




@end

0 comments on commit 55d71b1

Please sign in to comment.