Skip to content
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
7 changes: 6 additions & 1 deletion iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,12 @@ + (void)addNotificationRequest:(OSNotificationPayload*)payload

// Synchroneously downloads a media
// On success returns bundle resource name, otherwise returns nil
+ (NSString*)downloadMediaAndSaveInBundle:(NSString*)url {
+ (NSString*)downloadMediaAndSaveInBundle:(NSString*)urlString {

let inputUrl = [NSURL URLWithString:urlString];

//removes any unnecessary query parameters that would break extension type checking
let url = [[NSURL alloc] initWithScheme:inputUrl.scheme host:inputUrl.host path:inputUrl.path].absoluteString;

NSArray<NSString*>* supportedExtensions = @[@"aiff", @"wav", @"mp3", @"mp4", @"jpg", @"jpeg", @"png", @"gif", @"mpeg", @"mpg", @"avi", @"m4a", @"m4v"];
NSArray* components = [url componentsSeparatedByString:@"."];
Expand Down
13 changes: 13 additions & 0 deletions iOS_SDK/OneSignalSDK/UnitTests/UnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
#import "OneSignalClientOverrider.h"
#import "OneSignalCommonDefines.h"

@interface OneSignalHelper (TestHelper)
+ (NSString*)downloadMediaAndSaveInBundle:(NSString*)urlString;
@end


@interface UnitTests : XCTestCase

Expand Down Expand Up @@ -1811,4 +1815,13 @@ -(void)testDelayedSubscriptionUpdate {
XCTAssertTrue(observer->last.to.subscribed);
}

// Checks to make sure that media URL's will not fail the extension-type check if they have query parameters
- (void)testHandlingMediaUrlExtensions {
let testUrl = @"https://images.pexels.com/photos/104827/cat-pet-animal-domestic-104827.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=100";

let cacheName = [OneSignalHelper downloadMediaAndSaveInBundle:testUrl];

XCTAssertNotNil(cacheName);
}

@end