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

feat(iOS): expose new APIs timeoutForResource and waitsForConnectivity #53

Merged
merged 2 commits into from
Aug 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion APSHTTPClient.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal\n\n# Step 1. Build Device and Simulator versions\nfor sdk in iphoneos iphonesimulator; do\nxcodebuild -target APSHTTPClient -configuration ${CONFIGURATION} -sdk ${sdk} BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" OTHER_CFLAGS=\"-fembed-bitcode\" CLANG_ENABLE_MODULE_DEBUGGING=NO GCC_PRECOMPILE_PREFIX_HEADER=NO DEBUG_INFORMATION_FORMAT=\"DWARF with dSYM\"\ndone\n\nmkdir -p \"${UNIVERSAL_OUTPUTFOLDER}\"\n\n# Step 2. Create universal binary file using lipo\nlipo -create -output \"${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a\" \"${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a\" \"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a\"\n\n# Last touch. copy the header files. Just for convenience\ncp -R ${BUILD_DIR}/${CONFIGURATION}-iphoneos/include/APSHTTPClient/* \"${UNIVERSAL_OUTPUTFOLDER}/\"\n\nopen \"${UNIVERSAL_OUTPUTFOLDER}\"\n";
shellScript = "UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal\n\nXCODE_VERSION=$(/usr/libexec/PlistBuddy -c \"Print :DTXcode\" \"$(xcode-select -p)/../Info.plist\")\n# Step 1. Build for Simulator\n\n# Exclude arm64 architecture from simulator build in XCode 12+- TIMOB-28075\n\n if [[ $XCODE_VERSION -ge 1200 ]]; then\n xcodebuild -target APSHTTPClient -configuration ${CONFIGURATION} -sdk iphonesimulator EXCLUDED_ARCHS=arm64 BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" OTHER_CFLAGS=\"-fembed-bitcode\" CLANG_ENABLE_MODULE_DEBUGGING=NO GCC_PRECOMPILE_PREFIX_HEADER=NO DEBUG_INFORMATION_FORMAT=\"DWARF with dSYM\"\n else\n xcodebuild -target APSHTTPClient -configuration ${CONFIGURATION} -sdk iphonesimulator BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" OTHER_CFLAGS=\"-fembed-bitcode\" CLANG_ENABLE_MODULE_DEBUGGING=NO GCC_PRECOMPILE_PREFIX_HEADER=NO DEBUG_INFORMATION_FORMAT=\"DWARF with dSYM\"\n fi\n\n# Step 2. Build for Device\nxcodebuild -target APSHTTPClient -configuration ${CONFIGURATION} -sdk iphoneos BUILD_DIR=\"${BUILD_DIR}\" BUILD_ROOT=\"${BUILD_ROOT}\" OTHER_CFLAGS=\"-fembed-bitcode\" CLANG_ENABLE_MODULE_DEBUGGING=NO GCC_PRECOMPILE_PREFIX_HEADER=NO DEBUG_INFORMATION_FORMAT=\"DWARF with dSYM\"\n\nmkdir -p \"${UNIVERSAL_OUTPUTFOLDER}\"\n\n# Step 3. Create universal binary file using lipo\nlipo -create -output \"${UNIVERSAL_OUTPUTFOLDER}/lib${PROJECT_NAME}.a\" \"${BUILD_DIR}/${CONFIGURATION}-iphoneos/lib${PROJECT_NAME}.a\" \"${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/lib${PROJECT_NAME}.a\"\n\n# Last touch. copy the header files. Just for convenience\ncp -R ${BUILD_DIR}/${CONFIGURATION}-iphoneos/include/APSHTTPClient/* \"${UNIVERSAL_OUTPUTFOLDER}/\"\n\nopen \"${UNIVERSAL_OUTPUTFOLDER}\"\n";
};
/* End PBXShellScriptBuildPhase section */

Expand Down
3 changes: 2 additions & 1 deletion APSHTTPClient/APSHTTPRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ typedef NS_ENUM(NSInteger, APSRequestError) {
@property (nonatomic, assign, readwrite) BOOL cancelled;
@property (nonatomic, assign, readwrite) NSURLRequestCachePolicy cachePolicy;
@property (nonatomic, assign, readonly, getter=isReady) BOOL ready;

@property (nonatomic, assign, readwrite) BOOL waitsForConnectivity;
@property (nonatomic, assign, readwrite) NSTimeInterval timeoutForResource;
/*!
@discussion Set to YES to block the caller's thread for the duration
of the network call. In this case the queue property is ignored. The
Expand Down
15 changes: 13 additions & 2 deletions APSHTTPClient/APSHTTPRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ - (id)init
_sendDefaultCookies = YES;
_redirects = YES;
_validatesSecureCertificate = YES;
_waitsForConnectivity = NO;
_headers = [[NSMutableDictionary alloc] init];
_runModes = @[ NSDefaultRunLoopMode ];
_request = [[NSMutableURLRequest alloc] init];
Expand Down Expand Up @@ -116,13 +117,23 @@ - (void)send
[self.request setHTTPShouldHandleCookies:self.sendDefaultCookies];
[self.request setCachePolicy:self.cachePolicy];

NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];

if (self.timeoutForResource > 0) {
sessionConfiguration.timeoutIntervalForResource = self.timeoutForResource;
}

if (@available(iOS 11.0, *)) {
sessionConfiguration.waitsForConnectivity = self.waitsForConnectivity;
}

if (self.synchronous) {
if (self.requestUsername != nil && self.requestPassword != nil && [self.request valueForHTTPHeaderField:@"Authorization"] == nil) {
NSString *authString = [APSHTTPHelper base64encode:[[NSString stringWithFormat:@"%@:%@", self.requestUsername, self.requestPassword] dataUsingEncoding:NSUTF8StringEncoding]];
[self.request setValue:[NSString stringWithFormat:@"Basic %@", authString] forHTTPHeaderField:@"Authorization"];
}
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
self.session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:self.theQueue];
self.session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:self.theQueue];
self.task = [self.session dataTaskWithRequest:self.request
completionHandler:^(NSData *__nullable data, NSURLResponse *__nullable response, NSError *__nullable error) {
[self.response appendData:data];
Expand All @@ -142,7 +153,7 @@ - (void)send
[self.response setReadyState:APSHTTPResponseStateOpened];
[self invokeCallbackWithState:APSHTTPCallbackStateReadyState];

self.session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:nil];
self.session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:nil];
self.task = [self.session dataTaskWithRequest:self.request];
[self.task resume];
}
Expand Down