Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using reflection for iOS 13 API writeData:error: #1030

Merged
merged 1 commit into from
Dec 14, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions iOS_SDK/OneSignalSDK/Source/OneSignalHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,23 @@ @implementation DirectDownloadDelegate
@synthesize error, response, done;

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