Skip to content

Commit

Permalink
Merge pull request #1029 from OneSignal/fix/attachment_handler_crashes
Browse files Browse the repository at this point in the history
Fix crashes when failing to download Notification attachments
  • Loading branch information
emawby authored Dec 14, 2021
2 parents fd06483 + 021f274 commit d975c61
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,23 @@ @implementation DirectDownloadDelegate
@synthesize error, response, done;

-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
[outputHandle writeData:data];
NSError *fileHandleError;
if (@available(iOS 13.0, *)) {
[outputHandle writeData:data error:&fileHandleError];
} else {
@try {
[outputHandle writeData:data];
} @catch (NSException *e) {
NSDictionary *userInfo = @{
NSLocalizedDescriptionKey : @"Failed to write attachment data to filehandle",
};
fileHandleError = [NSError errorWithDomain:@"com.onesignal.download" code:0 userInfo:userInfo];
}
}

if (fileHandleError != nil) {
[OneSignal onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"OneSignal Error encountered while downloading attachment: %@", fileHandleError.localizedDescription]];
}
}

- (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveResponse:(NSURLResponse *)aResponse completionHandler:(void (^)(NSURLSessionResponseDisposition))completionHandler {
Expand Down

0 comments on commit d975c61

Please sign in to comment.