diff --git a/Parse/PFPush.m b/Parse/PFPush.m index 07eb36209..608eac5a0 100644 --- a/Parse/PFPush.m +++ b/Parse/PFPush.m @@ -415,7 +415,7 @@ + (void)handlePush:(NSDictionary *)userInfo { NSString *soundName = aps[@"sound"]; - if (soundName.length == 0 || [soundName isEqualToString:@"default"]) { + if ((id)soundName == [NSNull null] || soundName.length == 0 || [soundName isEqualToString:@"default"]) { [[self pushInternalUtilClass] playVibrate]; } else { [[self pushInternalUtilClass] playAudioWithName:soundName]; diff --git a/Tests/Unit/PushMobileTests.m b/Tests/Unit/PushMobileTests.m index e050c1460..74100b515 100644 --- a/Tests/Unit/PushMobileTests.m +++ b/Tests/Unit/PushMobileTests.m @@ -54,4 +54,21 @@ - (void)testHandlePushDictionaryAlert { OCMVerifyAll(mockedUtils); } +- (void)testHandlePushWithNullSound { + id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils)); + OCMExpect([mockedUtils showAlertViewWithTitle:[OCMArg isNil] message:@"hello"]); + OCMExpect([mockedUtils playVibrate]); + + // NOTE: Async parse preload step may call this selector. + // Don't epxect it because it doesn't ALWAYs get to this point before returning from the method. + OCMStub([mockedUtils getDeviceTokenFromKeychain]).andReturn(nil); + + [PFPush setPushInternalUtilClass:mockedUtils]; + [PFPush handlePush:@{ @"aps" : @{@"alert" : @"hello", @"sound": [NSNull null]} }]; + + OCMVerifyAll(mockedUtils); + + [PFPush setPushInternalUtilClass:nil]; +} + @end