Play vibration in PFPush.handlePush() only if default sound is specified.

This commit is contained in:
Nikita Lutsenko
2015-09-03 12:45:42 -07:00
parent ff178c44e2
commit caed7d0129
2 changed files with 41 additions and 8 deletions

View File

@@ -415,12 +415,15 @@ static Class _pushInternalUtilClass = nil;
NSString *soundName = aps[@"sound"];
if ((id)soundName == [NSNull null] || soundName.length == 0 || [soundName isEqualToString:@"default"]) {
[[self pushInternalUtilClass] playVibrate];
} else {
[[self pushInternalUtilClass] playAudioWithName:soundName];
// Vibrate or play sound only if `sound` is specified.
if ([soundName isKindOfClass:[NSString class]] && soundName.length != 0) {
// Vibrate if the sound is `default`, otherwise - play the sound name.
if ([soundName isEqualToString:@"default"]) {
[[self pushInternalUtilClass] playVibrate];
} else {
[[self pushInternalUtilClass] playAudioWithName:soundName];
}
}
}
#endif

View File

@@ -22,7 +22,6 @@
- (void)testHandlePushStringAlert {
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.
@@ -39,7 +38,6 @@
- (void)testHandlePushDictionaryAlert {
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
OCMExpect([mockedUtils showAlertViewWithTitle:[OCMArg isNil] message:@"hello bob 1"]);
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.
@@ -57,7 +55,6 @@
- (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.
@@ -71,4 +68,37 @@
[PFPush setPushInternalUtilClass:nil];
}
- (void)testHandlePushWithDefaultSound {
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": @"default"} }];
OCMVerifyAll(mockedUtils);
[PFPush setPushInternalUtilClass:nil];
}
- (void)testHandlePushWithCustomSound {
id mockedUtils = PFStrictProtocolMock(@protocol(PFPushInternalUtils));
OCMExpect([mockedUtils playAudioWithName:@"yolo"]);
// 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" : @{@"sound": @"yolo"} }];
OCMVerifyAll(mockedUtils);
[PFPush setPushInternalUtilClass:nil];
}
@end