From 242171a6b3b655612820911203aea14476e3ce96 Mon Sep 17 00:00:00 2001 From: Dominik Krejcik Date: Mon, 17 Aug 2015 17:52:42 +0100 Subject: [PATCH] Fix a crash when receiving a push notification with null sound --- Parse/PFPush.m | 2 +- Tests/Unit/PushMobileTests.m | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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