Skip to content

Commit f5cac1e

Browse files
committed
Fixing collapseId and writeData reflection after rebase
1 parent 4adf4e3 commit f5cac1e

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

iOS_SDK/OneSignalSDK/OneSignalCore/Source/OSNotification.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@
9696
/* iOS 15+ : Interruption Level */
9797
@property(readonly)NSString *interruptionLevel;
9898

99+
@property(readonly, nullable)NSString *collapseId;
100+
99101
/* Parses an APNS push payload into a OSNotification object.
100102
Useful to call from your NotificationServiceExtension when the
101103
didReceiveNotificationRequest:withContentHandler: method fires. */

iOS_SDK/OneSignalSDK/OneSignalExtension/OneSignalAttachmentHandler.m

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,37 @@ @implementation DirectDownloadDelegate
4646
@synthesize error, response, done;
4747

4848
-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
49-
[outputHandle writeData:data];
49+
NSError * __autoreleasing fileHandleError;
50+
NSError * __autoreleasing *fileHandleErrorPointer = &fileHandleError;
51+
if (@available(iOS 13.0, *)) {
52+
// We need to use NSInvocation for reflection because performSelector cannot take pointer parameters
53+
SEL writeDataSelector = NSSelectorFromString(@"writeData:error:");
54+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSFileHandle instanceMethodSignatureForSelector:writeDataSelector]];
55+
[invocation setTarget:outputHandle];
56+
[invocation setSelector:writeDataSelector];
57+
/*
58+
From Apple's Documentation on NSInvocation:
59+
Indices 0 and 1 indicate the hidden arguments self and _cmd, respectively;
60+
you should set these values directly with the target and selector properties.
61+
Use indices 2 and greater for the arguments normally passed in a message.
62+
*/
63+
[invocation setArgument:&data atIndex:2];
64+
[invocation setArgument:&fileHandleErrorPointer atIndex:3];
65+
[invocation invoke];
66+
} else {
67+
@try {
68+
[outputHandle writeData:data];
69+
} @catch (NSException *e) {
70+
NSDictionary *userInfo = @{
71+
NSLocalizedDescriptionKey : @"Failed to write attachment data to filehandle",
72+
};
73+
fileHandleError = [NSError errorWithDomain:@"com.onesignal.download" code:0 userInfo:userInfo];
74+
}
75+
}
76+
77+
if (fileHandleError != nil) {
78+
[OneSignalLog onesignalLog:ONE_S_LL_ERROR message:[NSString stringWithFormat:@"OneSignal Error encountered while downloading attachment: %@", fileHandleError.localizedDescription]];
79+
}
5080
}
5181

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

0 commit comments

Comments
 (0)