Custom UserAgent 설정

개발/iOS 2020. 12. 10. 15:21
반응형
//--------------------------------------------------------
/// WKWebView (type 1 - Objective C)
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:CGRectZero];
[wkWebView loadHTMLString:@"<html></html>" baseURL:nil];
[wkWebView evaluateJavaScript:@"navigator.appName" completionHandler:^(id __nullable appName, NSError * __nullable error) {
    NSLog(@"%@", appName);
}];

[wkWebView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id __nullable userAgent, NSError * __nullable error) {
    NSLog(@"%@", userAgent);
    // iOS 8.3
    // Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F70
    // iOS 9.0
    // Mozilla/5.0 (iPhone; CPU iPhone OS 9_0 like Mac OS X) AppleWebKit/601.1.32 (KHTML, like Gecko) Mobile/13A4254v
    // Custom UserAgent
    NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
    NSString *newUserAgent = [NSString stringWithFormat:@"%@ %@", userAgent, appName];
    if (@available(iOS 9.0, *)) {
        wkWebView.customUserAgent = newUserAgent;
    } else {
        NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
        [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
    }
}];

//--------------------------------------------------------
/// WKWebView (type 2 - Objective C)
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
configuration.applicationNameForUserAgent = @"My Custom Useragent Name";
WKWebView *wkWebView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
NSLog(@"%@", wkWebView.configuration.applicationNameForUserAgent); // My Custom Useragent Name
NSLog(@"%@", wkWebView.customUserAgent); // null
[wkWebView loadHTMLString:@"<html></html>" baseURL:nil];
[wkWebView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id __nullable userAgent, NSError * __nullable error) {
    NSLog(@"%@", userAgent);
    // iOS 9
    // Mozilla/5.0 (iPhone; CPU iPhone OS 9_0 like Mac OS X) AppleWebKit/601.1.32 (KHTML, like Gecko) My Custom Useragent Name
}];

//--------------------------------------------------------
/// WKWebView (type 1 - Swift) Available: iOS 9+
wkWebView.evaluateJavaScript("navigator.userAgent") {
    [weak webView] (result, error) in
if let webView = webView, let userAgent = result as? String {
    webView.customUserAgent = userAgent + "/Custom Agent"
} }

//--------------------------------------------------------
/// WKWebView (type 1 - Swift) Available: iOS 9+
let webConfiguration = WKWebViewConfiguration()
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.customUserAgent = "ExampleApp/1.0 (iPhone)"

//--------------------------------------------------------
/// WKWebView (type 2 - Swift) Available: iOS 9+
/// Append to the default User Agent
let webConfiguration = WKWebViewConfiguration()
webConfiguration.applicationNameForUserAgent = "ExampleApp/1.0 (iPhone)"
let webView = WKWebView(frame: .zero, configuration: webConfiguration)
// Mozilla/5.0 (iPhone; CPU iPhone OS 11_2 like Mac OS X) AppleWebKit/604.4.7 (KHTML, like Gecko) ExampleApp/1.0 (iPhone)
 
//--------------------------------------------------------
/// UIWebView (Objective C)
UIWebView *webView = [[UIWebView alloc] init];
[webView loadHTMLString:@"<html></html>" baseURL:nil];
NSString *appName = [webView stringByEvaluatingJavaScriptFromString:@"navigator.appName"];
NSLog(@"%@", appName);
NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSLog(@"%@", userAgent);
// iOS 8.3
// Mozilla/5.0 (iPhone; CPU iPhone OS 8_3 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12F70
// iOS 9.0
// Mozilla/5.0 (iPhone; CPU iPhone OS 9_0 like Mac OS X) AppleWebKit/601.1.32 (KHTML, like Gecko) Mobile/13A4254v}

// Custom UserAgent
NSString *newUserAgent = [NSString stringWithFormat:@"%@ %@", userAgent, appName];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

//--------------------------------------------------------
/// UIWebView (Swift) Available: iOS 9+
webView.customUserAgent = (UIWebView().stringByEvaluatingJavaScript(from: "navigator.userAgent") ?? "") + "/Custom agent"



//--------------------------------------------------------
//--------------------------------------------------------
/// Example :

// UIWebView
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectZero];
NSString *userAgent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
NSString *newUserAgent = [NSString stringWithFormat:@"%@ %@", userAgent, appName];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil]; [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];

// WKWebView
WKWebView *wkWebView = [[WKWebView alloc]initWithFrame:CGRectZero];
[wkWebView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id userAgent, NSError *error) {
    NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
    NSString *newUserAgent = [NSString stringWithFormat:@"%@ %@", userAgent, appName];
    if (@available(iOS 9.0, *)) {
        wkWebView.customUserAgent = newUserAgent;
    } else {
        NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newUserAgent, @"UserAgent", nil];
        [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
    }
}];

 

2020/12/10 - [iOS/Tips] - Custom UserAgent 설정

2020/12/10 - [iOS/Tips] - CocoaPods 설치 및 제거

2020/12/10 - [iOS/Tips] - Clang diagnostic 경고 무시하기

2020/12/10 - [개발노트] - Bluetooth UUID

2020/12/08 - [개발노트] - 모바일 앱 메모리덤프 이슈 해결방법

2020/12/08 - [프로그래밍/Java Script] - Android, iOS 앱 설치여부 체크 및 스토어 이동

2020/08/21 - [Android/Tips] - aab파일 apk파일로 변환

2020/08/11 - [iOS/Swift] - WKWebView 화면 출력 완료 이벤트

2020/08/06 - [iOS/Tips] - 개발관련 폴더 경로

2020/07/19 - [Android/Tips] - 안드로이드 원격 디버깅 방법

2020/07/18 - [Android/Tips] - Cannot convert string value 'JETPACK_COMPOSE' to an enum value of type 'com.android.builder.model.AndroidGradlePluginProjectFlags$BooleanFlag' (valid case insensitive values: APPLICATION_R_CLASS_CONSTANT_IDS, TEST_R_CLASS_CONSTANT_IDS, TRANSITIVE_R_CLASS)

2020/07/18 - [Android/Tips] - OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

2020/07/17 - [iOS/Tips] - 웹에서 iOS 앱 설치여부 체크

2020/07/14 - [Android/Tips] - 웹에서 안드로이드 앱을 실행 (Custom URL Scheme)

2020/07/11 - [OS/Mac OS X] - SMC(System Management Controller) 재설정

반응형

'개발 > iOS' 카테고리의 다른 글

Fat Static Library 빌드 (2/2)  (0) 2020.12.10
Fat Static Library 빌드 (1/2)  (1) 2020.12.10
CocoaPods 설치 및 제거  (0) 2020.12.10
Clang diagnostic 경고 무시하기  (0) 2020.12.10
WKWebView 화면 출력 완료 이벤트  (0) 2020.08.11
블로그 이미지

SKY STORY

,
반응형

스마트폰 BTC 채굴앱

https://get.cryptobrowser.site/34473645

 

Earn coins while browsing the web

Earn bitcoins while watching videos, chatting, or playing online. It has never been so easy to increase your income! Tell your friends about CryptoTab Browser, invite them to join, and earn more together. Grow your network—get more profit!

get.cryptobrowser.site

 

 CocoaPods 설치
sudo gem install cocoapods

 CocoaPods 설정 pod setup

 버전 확인 pod —version

 CocoaPods 제거
sudo gem uninstall cocoapods
sudo gem uninstall cocoapods-core
sudo gem uninstall cocoapods-downloader sudo gem uninstall cocoapods-deintegrate sudo gem uninstall cocoapods-plugins sudo gem uninstall cocoapods-search sudo gem uninstall cocoapods-stats
sudo gem uninstall cocoapods-trunk
sudo gem uninstall cocoapods-try

 설치된 cocoapods 리스트 보기 gem list --local | grep cocoapods

 특정버전 제거
sudo gem uninstall cocoapods -v 0.20.2

 최신안정버전설치
sudo gem install cocoapods

 특정버전설치
sudo gem install cocoapods -v 0.38.0

 최신프리뷰버전설치
gem install cocoapods --pre

 

스마트폰 BTC 채굴앱

https://get.cryptobrowser.site/34473645

 

Earn coins while browsing the web

Earn bitcoins while watching videos, chatting, or playing online. It has never been so easy to increase your income! Tell your friends about CryptoTab Browser, invite them to join, and earn more together. Grow your network—get more profit!

get.cryptobrowser.site

 

2020/12/10 - [iOS/Tips] - Custom UserAgent 설정

2020/12/10 - [iOS/Tips] - CocoaPods 설치 및 제거

2020/12/10 - [iOS/Tips] - Clang diagnostic 경고 무시하기

2020/12/10 - [개발노트] - Bluetooth UUID

2020/12/08 - [개발노트] - 모바일 앱 메모리덤프 이슈 해결방법

2020/12/08 - [프로그래밍/Java Script] - Android, iOS 앱 설치여부 체크 및 스토어 이동

2020/08/21 - [Android/Tips] - aab파일 apk파일로 변환

2020/08/11 - [iOS/Swift] - WKWebView 화면 출력 완료 이벤트

2020/08/06 - [iOS/Tips] - 개발관련 폴더 경로

2020/07/19 - [Android/Tips] - 안드로이드 원격 디버깅 방법

2020/07/18 - [Android/Tips] - Cannot convert string value 'JETPACK_COMPOSE' to an enum value of type 'com.android.builder.model.AndroidGradlePluginProjectFlags$BooleanFlag' (valid case insensitive values: APPLICATION_R_CLASS_CONSTANT_IDS, TEST_R_CLASS_CONSTANT_IDS, TRANSITIVE_R_CLASS)

2020/07/18 - [Android/Tips] - OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended

2020/07/17 - [iOS/Tips] - 웹에서 iOS 앱 설치여부 체크

2020/07/14 - [Android/Tips] - 웹에서 안드로이드 앱을 실행 (Custom URL Scheme)

2020/07/11 - [OS/Mac OS X] - SMC(System Management Controller) 재설정

반응형

'개발 > iOS' 카테고리의 다른 글

Fat Static Library 빌드 (1/2)  (1) 2020.12.10
Custom UserAgent 설정  (0) 2020.12.10
Clang diagnostic 경고 무시하기  (0) 2020.12.10
WKWebView 화면 출력 완료 이벤트  (0) 2020.08.11
개발관련 폴더 경로  (0) 2020.08.06
블로그 이미지

SKY STORY

,
반응형

https://clang.llvm.org/docs/DiagnosticsReference.html http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html

컴파일 및 배포를 해도 상관은 없지만 Xcode Server에서 경고 메시지가 하나 이상 있다면 실패로 처리된다.
그래서 강제로 경고를 무시하게 할 필요가 있다.

다음과 같이 선언하면 경고를 무시할 수 있다.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "
경고가 발생하는 원인" // your code

#pragma clang diagnostic pop

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations" // your 
code

#pragma clang diagnostic pop

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow-ivar" // your code

#pragma GCC diagnostic pop

ex)
// 
로컬 선언을 사용하지 않으려면 인스턴스 변수를 숨김
#pragma clang diagnostic ignored "-Wshadow-ivar"
#pragma clang diagnostic ignored "-Wmismatched-return-types" #pragma clang diagnostic ignored "-Woverriding-method-mismatch" // 
폐기된 함수 또는 변수를 사용한 경우
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
// Extension 
및 부모 클래스에서 미리 selector를 사용하여 구현을 한 경우 #pragma clang diagnostic ignored "-Wundeclared-selector"

 

반응형

'개발 > iOS' 카테고리의 다른 글

Custom UserAgent 설정  (0) 2020.12.10
CocoaPods 설치 및 제거  (0) 2020.12.10
WKWebView 화면 출력 완료 이벤트  (0) 2020.08.11
개발관련 폴더 경로  (0) 2020.08.06
웹에서 iOS 앱 설치여부 체크  (0) 2020.07.17
블로그 이미지

SKY STORY

,
반응형

WKWebView 웹사이트 출력 완료 시점에 자동화 처리를 해야하는 경우가 종종있다.

이럴경우 다음과 같이 현재 페이지 로딩이 완료됬을 때 이벤트를 받아 처리할 수 있다.

func waitFullyLoaded(_ completionHandler: @escaping () -> Void) {
	webView.evaluateJavaScript("document.readyState === 'complete'") { (result, error) in
     	if let fullyLoaded = result as? Bool {
  			if !fullyLoaded || self.webView.isLoading {//not fully loaded yet
                DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                	self.waitFullyLoaded(completionHandler)
                }
            } else {// fully loaded
            	completionHandler()
        	}
    	}
	}
}
 
func test() {
	waitFullyLoaded { [weak self] in
	    guard let unwrappedSelf = self else { return }
    	unwrappedSelf.webView.evaluateJavaScript("javascript:main.payment();");
	}
}

 

반응형

'개발 > iOS' 카테고리의 다른 글

CocoaPods 설치 및 제거  (0) 2020.12.10
Clang diagnostic 경고 무시하기  (0) 2020.12.10
개발관련 폴더 경로  (0) 2020.08.06
웹에서 iOS 앱 설치여부 체크  (0) 2020.07.17
Dictionary sort  (0) 2020.07.11
블로그 이미지

SKY STORY

,
반응형

Derived Data

/Users/[ 사용자 계정 ]/Library/Developer/Xcode/DerivedData

 

Archives

/Users/[ 사용자 계정 ]/Library/Developer/Xcode/Archives

 

Simulator Components

/Library/Developer/CoreSimulator/Profiles/Runtimes

 

Provisioning Profiles:

/Users/[ 사용자 계정 ]/Library/MobileDevice/Provisioning\ Profiles

반응형

'개발 > iOS' 카테고리의 다른 글

Clang diagnostic 경고 무시하기  (0) 2020.12.10
WKWebView 화면 출력 완료 이벤트  (0) 2020.08.11
웹에서 iOS 앱 설치여부 체크  (0) 2020.07.17
Dictionary sort  (0) 2020.07.11
UTC시간, Locale시간 변경  (0) 2020.07.11
블로그 이미지

SKY STORY

,
반응형

앱링크를 타임아웃을 설정하고 앱을 실행되도록 하면 
앱이 설치되어 있을 경우 앱을 실행하게된다. 

setTimeout(function () { 
	window.location = "https://itunes.apple.com/app/앱 아이디"; 
}, 25);
window.location = "앱 스킴명://";

 

iOS 14.4.1 이후 위의 타임 트릭을 사용하여 앱 호출 시

앱 실행과 스토어 이동이 중복해서 발생하는 문제가 발생된다.

이 경우 Universal Link를 사용하도록 하자.

 

2021.03.16 - [iOS/Tips] - Universal Link (1/4) - 네이티브 환경설정

2021.03.16 - [iOS/Tips] - Universal Link (2/4) - 네이티브 링크 수신

2021.03.16 - [iOS/Tips] - Universal Link (3/4) - 웹서버 환경 설정

2021.03.16 - [iOS/Tips] - Universal Link (4/4) - 웹서버 환경 검증

2020/12/08 - [프로그래밍/Java Script] - Android, iOS 앱 설치여부 체크 및 스토어 이동

2020/12/14 - [iOS/Tips] - bundle id 알아내기

2020/12/12 - [AI/Algorithm] - 2D 충돌처리

2020/12/11 - [iOS/Swift] - UIViewController 스위칭

2020/12/11 - [개발노트] - PlantUML 설치 (Mac OS X)

2020/12/11 - [개발노트] - 특수문자 발음

2020/12/10 - [iOS/Objective-C] - 웹뷰에서 javascript 함수 동기식 호출

2020/12/10 - [iOS/Tips] - Fat Static Library 빌드 (2/2)

2020/12/10 - [iOS/Tips] - Fat Static Library 빌드 (1/2)

2020/12/10 - [iOS/Tips] - Custom UserAgent 설정

2020/12/10 - [iOS/Tips] - CocoaPods 설치 및 제거

2020/12/10 - [iOS/Tips] - Clang diagnostic 경고 무시하기

2020/12/10 - [개발노트] - Bluetooth UUID

 

반응형

'개발 > iOS' 카테고리의 다른 글

WKWebView 화면 출력 완료 이벤트  (0) 2020.08.11
개발관련 폴더 경로  (0) 2020.08.06
Dictionary sort  (0) 2020.07.11
UTC시간, Locale시간 변경  (0) 2020.07.11
SEED 블록암호 알고리즘 CBC (Cipher Block Chaining) 예제 (2/2)  (0) 2020.07.11
블로그 이미지

SKY STORY

,

Dictionary sort

개발/iOS 2020. 7. 11. 21:06
반응형
반응형
블로그 이미지

SKY STORY

,
반응형
// UTC 시간을 Locale 시간으로 변환
func utcToLocale(utcDate : String, dateFormat: String) -> String
{
	let dfFormat = DateFormatter()
	dfFormat.dateFormat = dateFormat
	dfFormat.timeZone = TimeZone(abbreviation: "UTC")
	let dtUtcDate = dfFormat.date(from: utcDate)
	
	dfFormat.timeZone = TimeZone.current
	dfFormat.dateFormat = dateFormat
	return dfFormat.string(from: dtUtcDate!)
}
    
// Locale 시간을 UTC 시간으로 변환
func localeToUtc(localeDate: String, dateFormat: String) -> String
{
	let dfFormat = DateFormatter()
	dfFormat.dateFormat = dateFormat
	dfFormat.timeZone = TimeZone.current
	let dtLocaleDate = dfFormat.date(from: localeDate)
	
	dfFormat.timeZone = TimeZone(abbreviation: "UTC")
	dfFormat.dateFormat = dateFormat
	return dfFormat.string(from: dtLocaleDate!)
}
반응형
블로그 이미지

SKY STORY

,