Skip to content

Commit 9f27d6f

Browse files
committed
Using reflection for iOS 13 API writeData:error:
We need to use NSInvocation for reflection because performSelector cannot take pointer parameters.
1 parent d975c61 commit 9f27d6f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,23 @@ @implementation DirectDownloadDelegate
7575
@synthesize error, response, done;
7676

7777
-(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data {
78-
NSError *fileHandleError;
78+
NSError * __autoreleasing fileHandleError;
79+
NSError * __autoreleasing *fileHandleErrorPointer = &fileHandleError;
7980
if (@available(iOS 13.0, *)) {
80-
[outputHandle writeData:data error:&fileHandleError];
81+
// We need to use NSInvocation for reflection because performSelector cannot take pointer parameters
82+
SEL writeDataSelector = NSSelectorFromString(@"writeData:error:");
83+
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSFileHandle instanceMethodSignatureForSelector:writeDataSelector]];
84+
[invocation setTarget:outputHandle];
85+
[invocation setSelector:writeDataSelector];
86+
/*
87+
From Apple's Documentation on NSInvocation:
88+
Indices 0 and 1 indicate the hidden arguments self and _cmd, respectively;
89+
you should set these values directly with the target and selector properties.
90+
Use indices 2 and greater for the arguments normally passed in a message.
91+
*/
92+
[invocation setArgument:&data atIndex:2];
93+
[invocation setArgument:&fileHandleErrorPointer atIndex:3];
94+
[invocation invoke];
8195
} else {
8296
@try {
8397
[outputHandle writeData:data];

0 commit comments

Comments
 (0)