Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions Parse/PFPush.m
Original file line number Diff line number Diff line change
Expand Up @@ -415,12 +415,15 @@ + (void)handlePush:(NSDictionary *)userInfo {

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

Expand Down
36 changes: 33 additions & 3 deletions Tests/Unit/PushMobileTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ @implementation PushMobileTests
- (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.
Expand All @@ -39,7 +38,6 @@ - (void)testHandlePushStringAlert {
- (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.
Expand All @@ -57,7 +55,6 @@ - (void)testHandlePushDictionaryAlert {
- (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.
Expand All @@ -71,4 +68,37 @@ - (void)testHandlePushWithNullSound {
[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