From 931b1516a671670ffc729f381e2681f0fd51d83f Mon Sep 17 00:00:00 2001 From: Brad Hesse Date: Tue, 8 May 2018 14:38:39 -0700 Subject: [PATCH 1/2] Miscellaneous Fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Fixes an issue where the download method for attachments wasn't correctly implemented with a double pointer. It accepted NSError as a parameter, but because this pointer gets copied, any new assignments will apply to the copied pointer, not the original. • Fixes an issue in setEmail() where the failure block was being called without verifying that it is nonnull, which could cause crashes. • Cleans up the notificationReceived() method, which created a string (actionSelected) but doesn't use it. --- iOS_SDK/OneSignalSDK/Source/OneSignal.m | 14 +++++--------- iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m | 13 ++++++------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignal.m b/iOS_SDK/OneSignalSDK/Source/OneSignal.m index 239c8c4a3..f93cef14d 100755 --- a/iOS_SDK/OneSignalSDK/Source/OneSignal.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignal.m @@ -1658,16 +1658,10 @@ + (void)notificationReceived:(NSDictionary*)messageDict isActive:(BOOL)isActive if (opened) { //app was in background / not running and opened due to a tap on a notification or an action check what type - NSString* actionSelected = NULL; OSNotificationActionType type = OSNotificationActionTypeOpened; - if (messageDict[@"custom"][@"a"][@"actionSelected"]) { - actionSelected = messageDict[@"custom"][@"a"][@"actionSelected"]; - type = OSNotificationActionTypeActionTaken; - } - if (messageDict[@"actionSelected"]) { - actionSelected = messageDict[@"actionSelected"]; + + if (messageDict[@"custom"][@"a"][@"actionSelected"] || messageDict[@"actionSelected"]) type = OSNotificationActionTypeActionTaken; - } // Call Action Block [OneSignal handleNotificationOpened:messageDict isActive:isActive actionType:type displayType:OneSignal.inFocusDisplayType]; @@ -2017,7 +2011,8 @@ + (void)setEmail:(NSString * _Nonnull)email withEmailAuthHashToken:(NSString * _ //checks to make sure that if email_auth is required, the user has passed in a hash token if (self.currentEmailSubscriptionState.requiresEmailAuth && (!emailAuthToken || emailAuthToken.length == 0)) { - failureBlock([NSError errorWithDomain:@"com.onesignal.email" code:0 userInfo:@{@"error" : @"Email authentication (auth token) is set to REQUIRED for this application. Please provide an auth token from your backend server or change the setting in the OneSignal dashboard."}]); + if (failureBlock) + failureBlock([NSError errorWithDomain:@"com.onesignal.email" code:0 userInfo:@{@"error" : @"Email authentication (auth token) is set to REQUIRED for this application. Please provide an auth token from your backend server or change the setting in the OneSignal dashboard."}]); return; } @@ -2205,6 +2200,7 @@ + (void)load { return; } + // Swizzle - UIApplication delegate injectToProperClass(@selector(setOneSignalDelegate:), @selector(setDelegate:), @[], [OneSignalAppDelegate class], [UIApplication class]); diff --git a/iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m b/iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m index 7bf1734b1..c67ee6303 100644 --- a/iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m +++ b/iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m @@ -108,12 +108,12 @@ - (id)initWithFilePath:(NSString*)path { @end @interface NSURLSession (DirectDownload) -+ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError *)error; ++ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError **)error; @end @implementation NSURLSession (DirectDownload) -+ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError *)error { ++ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError **)error { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; DirectDownloadDelegate *delegate = [[DirectDownloadDelegate alloc] initWithFilePath:localPath]; @@ -132,9 +132,8 @@ + (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error: NSError *downloadError = [delegate error]; if (downloadError != nil) { - if (error != nil) { - error = downloadError; - } + if (error) + *error = downloadError; return nil; } @@ -753,8 +752,8 @@ + (NSString*)downloadMediaAndSaveInBundle:(NSString*)urlString { //guard against situations where for example, available storage is too low @try { - NSError* error = nil; - let mimeType = [NSURLSession downloadItemAtURL:url toFile:filePath error:error]; + NSError* error; + let mimeType = [NSURLSession downloadItemAtURL:url toFile:filePath error:&error]; if (error) { [OneSignal onesignal_Log:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"Encountered an error while attempting to download file with URL: %@", error]]; From a9e5c408f0c0a6c2bb53a18b7f30807c0114c961 Mon Sep 17 00:00:00 2001 From: Brad Hesse Date: Thu, 10 May 2018 12:51:56 -0700 Subject: [PATCH 2/2] Fix Method Signature MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • A recent bug fix changed the signature of a helper method to synchronously download files • Fixes the method signature so the swizzled test override method works and doesn't crash the test --- iOS_SDK/OneSignalSDK/UnitTests/Shadows/NSURLSessionOverrider.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iOS_SDK/OneSignalSDK/UnitTests/Shadows/NSURLSessionOverrider.m b/iOS_SDK/OneSignalSDK/UnitTests/Shadows/NSURLSessionOverrider.m index 4fe0d07b0..6f3a52571 100644 --- a/iOS_SDK/OneSignalSDK/UnitTests/Shadows/NSURLSessionOverrider.m +++ b/iOS_SDK/OneSignalSDK/UnitTests/Shadows/NSURLSessionOverrider.m @@ -37,7 +37,7 @@ + (void)load { } // Override downloading of media attachment -+ (NSString *)overrideDownloadItemAtURL:(NSURL*)url toFile:(NSString*)localPath error:(NSError*)error { ++ (NSString *)overrideDownloadItemAtURL:(NSURL*)url toFile:(NSString*)localPath error:(NSError**)error { NSString *content = @"File Contents"; NSData *fileContents = [content dataUsingEncoding:NSUTF8StringEncoding]; [[NSFileManager defaultManager] createFileAtPath:localPath