Skip to content

Commit 54f9a19

Browse files
authored
Miscellaneous Fixes (#370)
* Miscellaneous Fixes • 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. * Fix Method Signature • 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
1 parent 5f65589 commit 54f9a19

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignal.m

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,16 +1658,10 @@ + (void)notificationReceived:(NSDictionary*)messageDict isActive:(BOOL)isActive
16581658

16591659
if (opened) {
16601660
//app was in background / not running and opened due to a tap on a notification or an action check what type
1661-
NSString* actionSelected = NULL;
16621661
OSNotificationActionType type = OSNotificationActionTypeOpened;
1663-
if (messageDict[@"custom"][@"a"][@"actionSelected"]) {
1664-
actionSelected = messageDict[@"custom"][@"a"][@"actionSelected"];
1665-
type = OSNotificationActionTypeActionTaken;
1666-
}
1667-
if (messageDict[@"actionSelected"]) {
1668-
actionSelected = messageDict[@"actionSelected"];
1662+
1663+
if (messageDict[@"custom"][@"a"][@"actionSelected"] || messageDict[@"actionSelected"])
16691664
type = OSNotificationActionTypeActionTaken;
1670-
}
16711665

16721666
// Call Action Block
16731667
[OneSignal handleNotificationOpened:messageDict isActive:isActive actionType:type displayType:OneSignal.inFocusDisplayType];
@@ -2017,7 +2011,8 @@ + (void)setEmail:(NSString * _Nonnull)email withEmailAuthHashToken:(NSString * _
20172011

20182012
//checks to make sure that if email_auth is required, the user has passed in a hash token
20192013
if (self.currentEmailSubscriptionState.requiresEmailAuth && (!emailAuthToken || emailAuthToken.length == 0)) {
2020-
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."}]);
2014+
if (failureBlock)
2015+
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."}]);
20212016
return;
20222017
}
20232018

@@ -2205,6 +2200,7 @@ + (void)load {
22052200
return;
22062201
}
22072202

2203+
22082204
// Swizzle - UIApplication delegate
22092205
injectToProperClass(@selector(setOneSignalDelegate:), @selector(setDelegate:), @[], [OneSignalAppDelegate class], [UIApplication class]);
22102206

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ - (id)initWithFilePath:(NSString*)path {
108108
@end
109109

110110
@interface NSURLSession (DirectDownload)
111-
+ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError *)error;
111+
+ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError **)error;
112112
@end
113113

114114
@implementation NSURLSession (DirectDownload)
115115

116-
+ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError *)error {
116+
+ (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:(NSError **)error {
117117
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
118118

119119
DirectDownloadDelegate *delegate = [[DirectDownloadDelegate alloc] initWithFilePath:localPath];
@@ -132,9 +132,8 @@ + (NSString *)downloadItemAtURL:(NSURL *)url toFile:(NSString *)localPath error:
132132

133133
NSError *downloadError = [delegate error];
134134
if (downloadError != nil) {
135-
if (error != nil) {
136-
error = downloadError;
137-
}
135+
if (error)
136+
*error = downloadError;
138137
return nil;
139138
}
140139

@@ -753,8 +752,8 @@ + (NSString*)downloadMediaAndSaveInBundle:(NSString*)urlString {
753752
//guard against situations where for example, available storage is too low
754753

755754
@try {
756-
NSError* error = nil;
757-
let mimeType = [NSURLSession downloadItemAtURL:url toFile:filePath error:error];
755+
NSError* error;
756+
let mimeType = [NSURLSession downloadItemAtURL:url toFile:filePath error:&error];
758757

759758
if (error) {
760759
[OneSignal onesignal_Log:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"Encountered an error while attempting to download file with URL: %@", error]];

iOS_SDK/OneSignalSDK/UnitTests/Shadows/NSURLSessionOverrider.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ + (void)load {
3737
}
3838

3939
// Override downloading of media attachment
40-
+ (NSString *)overrideDownloadItemAtURL:(NSURL*)url toFile:(NSString*)localPath error:(NSError*)error {
40+
+ (NSString *)overrideDownloadItemAtURL:(NSURL*)url toFile:(NSString*)localPath error:(NSError**)error {
4141
NSString *content = @"File Contents";
4242
NSData *fileContents = [content dataUsingEncoding:NSUTF8StringEncoding];
4343
[[NSFileManager defaultManager] createFileAtPath:localPath

0 commit comments

Comments
 (0)