Skip to content

Commit 2cdd245

Browse files
committed
Merge pull request #29 from dominikkrejcik/fix-null-sound-crash
Fix a crash when receiving a push notification with null sound
2 parents 4e5e507 + 242171a commit 2cdd245

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Parse/PFPush.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ + (void)handlePush:(NSDictionary *)userInfo {
415415

416416
NSString *soundName = aps[@"sound"];
417417

418-
if (soundName.length == 0 || [soundName isEqualToString:@"default"]) {
418+
if ((id)soundName == [NSNull null] || soundName.length == 0 || [soundName isEqualToString:@"default"]) {
419419
[[self pushInternalUtilClass] playVibrate];
420420
} else {
421421
[[self pushInternalUtilClass] playAudioWithName:soundName];

Tests/Unit/PushMobileTests.m

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,21 @@ - (void)testHandlePushDictionaryAlert {
5454
OCMVerifyAll(mockedUtils);
5555
}
5656

57+
- (void)testHandlePushWithNullSound {
58+
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
59+
OCMExpect([mockedUtils showAlertViewWithTitle:[OCMArg isNil] message:@"hello"]);
60+
OCMExpect([mockedUtils playVibrate]);
61+
62+
// NOTE: Async parse preload step may call this selector.
63+
// Don't epxect it because it doesn't ALWAYs get to this point before returning from the method.
64+
OCMStub([mockedUtils getDeviceTokenFromKeychain]).andReturn(nil);
65+
66+
[PFPush setPushInternalUtilClass:mockedUtils];
67+
[PFPush handlePush:@{ @"aps" : @{@"alert" : @"hello", @"sound": [NSNull null]} }];
68+
69+
OCMVerifyAll(mockedUtils);
70+
71+
[PFPush setPushInternalUtilClass:nil];
72+
}
73+
5774
@end

0 commit comments

Comments
 (0)