Skip to content

Commit d975c61

Browse files
authored
Merge pull request #1029 from OneSignal/fix/attachment_handler_crashes
Fix crashes when failing to download Notification attachments
2 parents fd06483 + 021f274 commit d975c61

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,23 @@ @implementation DirectDownloadDelegate
7575
@synthesize error, response, done;
7676

7777
-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
78-
[outputHandle writeData:data];
78+
NSError *fileHandleError;
79+
if (@available(iOS 13.0, *)) {
80+
[outputHandle writeData:data error:&fileHandleError];
81+
} else {
82+
@try {
83+
[outputHandle writeData:data];
84+
} @catch (NSException *e) {
85+
NSDictionary *userInfo = @{
86+
NSLocalizedDescriptionKey : @"Failed to write attachment data to filehandle",
87+
};
88+
fileHandleError = [NSError errorWithDomain:@"com.onesignal.download" code:0 userInfo:userInfo];
89+
}
90+
}
91+
92+
if (fileHandleError != nil) {
93+
[OneSignal onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"OneSignal Error encountered while downloading attachment: %@", fileHandleError.localizedDescription]];
94+
}
7995
}
8096

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

0 commit comments

Comments
 (0)