mirror of
https://github.com/tappollo/Parse-SDK-iOS-OSX.git
synced 2026-04-29 13:25:37 +08:00
Play vibration in PFPush.handlePush() only if default sound is specified.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user