Skip to content

Commit 13a6f08

Browse files
committed
Merge pull request #166 from ParsePlatform/nlutsenko.pushsound
Play vibration in PFPush.handlePush() only if default sound is specified.
2 parents c4fc445 + caed7d0 commit 13a6f08

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

Parse/PFPush.m

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,15 @@ + (void)handlePush:(NSDictionary *)userInfo {
415415

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

418-
if ((id)soundName == [NSNull null] || soundName.length == 0 || [soundName isEqualToString:@"default"]) {
419-
[[self pushInternalUtilClass] playVibrate];
420-
} else {
421-
[[self pushInternalUtilClass] playAudioWithName:soundName];
418+
// Vibrate or play sound only if `sound` is specified.
419+
if ([soundName isKindOfClass:[NSString class]] && soundName.length != 0) {
420+
// Vibrate if the sound is `default`, otherwise - play the sound name.
421+
if ([soundName isEqualToString:@"default"]) {
422+
[[self pushInternalUtilClass] playVibrate];
423+
} else {
424+
[[self pushInternalUtilClass] playAudioWithName:soundName];
425+
}
422426
}
423-
424427
}
425428
#endif
426429

Tests/Unit/PushMobileTests.m

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ @implementation PushMobileTests
2222
- (void)testHandlePushStringAlert {
2323
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
2424
OCMExpect([mockedUtils showAlertViewWithTitle:[OCMArg isNil] message:@"hello"]);
25-
OCMExpect([mockedUtils playVibrate]);
2625

2726
// NOTE: Async parse preload step may call this selector.
2827
// Don't epxect it because it doesn't ALWAYs get to this point before returning from the method.
@@ -39,7 +38,6 @@ - (void)testHandlePushStringAlert {
3938
- (void)testHandlePushDictionaryAlert {
4039
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
4140
OCMExpect([mockedUtils showAlertViewWithTitle:[OCMArg isNil] message:@"hello bob 1"]);
42-
OCMExpect([mockedUtils playVibrate]);
4341

4442
// NOTE: Async parse preload step may call this selector.
4543
// Don't epxect it because it doesn't ALWAYs get to this point before returning from the method.
@@ -57,7 +55,6 @@ - (void)testHandlePushDictionaryAlert {
5755
- (void)testHandlePushWithNullSound {
5856
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
5957
OCMExpect([mockedUtils showAlertViewWithTitle:[OCMArg isNil] message:@"hello"]);
60-
OCMExpect([mockedUtils playVibrate]);
6158

6259
// NOTE: Async parse preload step may call this selector.
6360
// Don't epxect it because it doesn't ALWAYs get to this point before returning from the method.
@@ -71,4 +68,37 @@ - (void)testHandlePushWithNullSound {
7168
[PFPush setPushInternalUtilClass:nil];
7269
}
7370

71+
- (void)testHandlePushWithDefaultSound {
72+
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
73+
OCMExpect([mockedUtils showAlertViewWithTitle:[OCMArg isNil] message:@"hello"]);
74+
OCMExpect([mockedUtils playVibrate]);
75+
76+
// NOTE: Async parse preload step may call this selector.
77+
// Don't epxect it because it doesn't ALWAYs get to this point before returning from the method.
78+
OCMStub([mockedUtils getDeviceTokenFromKeychain]).andReturn(nil);
79+
80+
[PFPush setPushInternalUtilClass:mockedUtils];
81+
[PFPush handlePush:@{ @"aps" : @{@"alert" : @"hello", @"sound": @"default"} }];
82+
83+
OCMVerifyAll(mockedUtils);
84+
85+
[PFPush setPushInternalUtilClass:nil];
86+
}
87+
88+
- (void)testHandlePushWithCustomSound {
89+
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
90+
OCMExpect([mockedUtils playAudioWithName:@"yolo"]);
91+
92+
// NOTE: Async parse preload step may call this selector.
93+
// Don't epxect it because it doesn't ALWAYs get to this point before returning from the method.
94+
OCMStub([mockedUtils getDeviceTokenFromKeychain]).andReturn(nil);
95+
96+
[PFPush setPushInternalUtilClass:mockedUtils];
97+
[PFPush handlePush:@{ @"aps" : @{@"sound": @"yolo"} }];
98+
99+
OCMVerifyAll(mockedUtils);
100+
101+
[PFPush setPushInternalUtilClass:nil];
102+
}
103+
74104
@end

0 commit comments

Comments
 (0)