Skip to content

Instantly share code, notes, and snippets.

View tigi44's full-sized avatar

tigi44 tigi44

View GitHub Profile
@tigi44
tigi44 / ignoreWebAuthSSL.mm
Last active January 26, 2021 03:08
wkwebview - ignore web auth (ssl..)
- (void)webView:(WKWebView *)webView didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition, NSURLCredential * _Nullable))completionHandler
{
NSURLSessionAuthChallengeDisposition disposition = NSURLSessionAuthChallengeUseCredential;
NSURLCredential *credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
if (completionHandler)
{
completionHandler(disposition, credential);
}
}
@tigi44
tigi44 / ignoreAuthSSL.mm
Last active January 26, 2021 03:07
NSURLSession - ignore auth ssl
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];
// <NSURLSessionTaskDelegate>
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge completionHandler:(void (^)(NSURLSessionAuthChallengeDisposition disposition, NSURLCredential *credential))completionHandler
{
completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
}
@tigi44
tigi44 / UIActivityViewControllerShareFile.m
Last active May 20, 2020 08:44
[iOS, Objective-c] UIActivityViewController : Share File
// UIActivityViewController
NSURL *sFilePathURL = [NSURL fileURLWithPath:aFilePath];
UIActivityViewController *sActivityController = [[UIActivityViewController alloc] initWithActivityItems:@[sFilePathURL] applicationActivities:nil];
[self presentViewController:sActivityController animated:YES completion:nil];
@tigi44
tigi44 / dataTaskFromRequest.m
Last active May 20, 2020 08:57
[iOS, Objective-c] File Download (HTTP Response attachment)
+ (void)dataTaskFromRequest:(NSURLRequest *)aRequest fileName:(NSString *)aFileName
{
NSURLSessionConfiguration *sSessionConfiguration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *sSession = [NSURLSession sessionWithConfiguration:sSessionConfiguration];
NSURLSessionDataTask *sPostDataTask = [sSession dataTaskWithRequest:aRequest
completionHandler:^(NSData *aData, NSURLResponse *aResponse, NSError *aError) {
if (!aError) {
@tigi44
tigi44 / webviewAttachmentFileDownload.m
Created May 20, 2020 08:48
[iOS, Objective-c] File Download (HTTP Response attachment)
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
{
BOOL sIsFileDownload = NO;
NSURL *sURL = navigationResponse.response.URL;
NSString *sMIMEType = navigationResponse.response.MIMEType;
NSString *sFileName = navigationResponse.response.suggestedFilename;
NSDictionary *sHeaders = ((NSHTTPURLResponse *)navigationResponse.response).allHeaderFields;
NSString *sContentDisposition = sHeaders[@"Content-Disposition"];
@tigi44
tigi44 / WKNavigationDelegateCookies.m
Last active September 21, 2021 19:58
[iOS, Objective-c] WebView Cookies (WKWebView, UIWebView)
// Get Cookies from a response
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationResponse:(WKNavigationResponse *)navigationResponse decisionHandler:(void (^)(WKNavigationResponsePolicy))decisionHandler
{
NSDictionary *sHeaders = ((NSHTTPURLResponse *)navigationResponse.response).allHeaderFields;
NSArray *sCookies = [NSHTTPCookie cookiesWithResponseHeaderFields:sHeaders forURL:sURL];
for (NSHTTPCookie *sCookie in sCookies) {
@tigi44
tigi44 / NSHTTPCookieStorage.m
Created May 20, 2020 08:54
[iOS, Objective-c] WebView Cookies (WKWebView, UIWebView)
// Setup Cookies policy
[NSHTTPCookieStorage sharedHTTPCookieStorage].cookieAcceptPolicy = NSHTTPCookieAcceptPolicyAlways;
// Get Cookies from NSHTTPCookieStorage
NSArray<NSHTTPCookie *> *sCookies = [NSHTTPCookieStorage sharedHTTPCookieStorage].cookies;
@tigi44
tigi44 / wkwebviewUserAgent.m
Created May 21, 2020 01:30
[iOS, Objective-c] WKWebView Custom User-Agent
- (void)setupCustomUserAgent
{
[self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(NSString *aUserAgent, NSError *aError) {
NSString *sCustomUserAgent = @"additional custom user-agent";
if (aUserAgent.length > 0 && aError == nil) {
sCustomUserAgent = [NSString stringWithFormat:@"%@ %@", aUserAgent, sCustomUserAgent];
}
@tigi44
tigi44 / carrier.mm
Created May 25, 2020 07:46
objective-c carrier
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#import <CoreTelephony/CTCarrier.h>
...
if (@available(iOS 12.0, *)) {
NSDictionary<NSString *, CTCarrier *> *dicCarrier = [[CTTelephonyNetworkInfo new] serviceSubscriberCellularProviders];
for (id key in dicCarrier) {
NSLog(@"key: %@, carrierName: %@", key, [[dicCarrier objectForKey:key] carrierName]);
}
@tigi44
tigi44 / jenkins_build.sh
Created May 25, 2020 08:00
remote build iOS Xcode Project(+ project version up) on Jenkins Server using shell script
#!/bin/bash
PROJECT_PATH='PROJECT_PATH'
XCODE_PROJECT_FILE_PATH='XCODE_PROJECT_FILE_PATH.xcodeproj/XCODE_PROJECT_FILE_PATH.pbxproj'
JENKINS_SERVER='JENKINS_SERVER'
function string_replace {
string=$1
old_string=$(echo $2 | sed 's#/#\\/#g')
new_string=$(echo $3 | sed 's#/#\\/#g')