Skip to content

Commit 118c69e

Browse files
committed
Trims white space around URLs
* Fixes issue where they would not open if their was any white space around them.
1 parent 1e22a38 commit 118c69e

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,9 +1287,10 @@ + (void)handleNotificationOpened:(NSDictionary*)messageDict
12871287
}
12881288

12891289
+ (void)launchWebURL:(NSString*)openUrl {
1290-
1291-
if (openUrl && [OneSignalHelper verifyURL:openUrl]) {
1292-
NSURL *url = [NSURL URLWithString:openUrl];
1290+
NSString* toOpenUrl = [OneSignalHelper trimURLSpacing:openUrl];
1291+
1292+
if (toOpenUrl && [OneSignalHelper verifyURL:toOpenUrl]) {
1293+
NSURL *url = [NSURL URLWithString:toOpenUrl];
12931294
// Give the app resume animation time to finish when tapping on a notification from the notification center.
12941295
// Isn't a requirement but improves visual flow.
12951296
[OneSignalHelper performSelector:@selector(displayWebView:) withObject:url afterDelay:0.5];

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
+ (NSString*)hashUsingMD5:(NSString*)string;
7979
+ (void)addAttachments:(NSDictionary*)attachments toNotificationContent:(id)content;
8080
+ (void)addActionButtons:(NSArray*)buttonsPayloadList toNotificationContent:(id)content;
81+
+ (NSString*)trimURLSpacing:(NSString*)url;
8182

8283
#pragma clang diagnostic pop
8384
@end

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,9 +813,10 @@ + (void)addAttachments:(NSDictionary*)attachments toNotificationContent:(UNMutab
813813
NSMutableArray *unAttachments = [NSMutableArray new];
814814

815815
for(id key in attachments) {
816-
NSString* URI = [attachments valueForKey:key];
816+
NSString* URI = [OneSignalHelper trimURLSpacing:[attachments valueForKey:key]];
817+
817818
NSURL* nsURL = [NSURL URLWithString:URI];
818-
819+
819820
// Remote media attachment */
820821
if (nsURL && [self isWWWScheme:nsURL]) {
821822
// Synchroneously download file and chache it
@@ -1078,6 +1079,13 @@ + (NSString*)hashUsingMD5:(NSString*)string {
10781079
return output;
10791080
}
10801081

1082+
+ (NSString*)trimURLSpacing:(NSString*)url {
1083+
if (!url)
1084+
return url;
1085+
1086+
return [url stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
1087+
}
1088+
10811089
#pragma clang diagnostic pop
10821090
#pragma clang diagnostic pop
10831091
#pragma clang diagnostic pop

0 commit comments

Comments
 (0)