2014-12-14 2 views
0

UIWebView의 사용자 에이전트 헤더를 변경하려고합니다. 나는 this SO answer을 팔로우하고 있습니다.viewdidload 후 uiwebview 사용자 에이전트 변경

registerDefaults 메서드를 viewDidLoad으로 호출하면 올바르게 작동합니다.

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Desktop", @"UserAgent", nil]; 
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; 
} 

그러나이 코드는 버튼을 클릭 한 후 호출해도 작동하지 않습니다.

- (IBAction)refreshButtonClicked:(id)sender { 
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Desktop", @"UserAgent", nil]; 
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; 
    [self.webView reload]; 
} 

또한 버튼 클릭시 WebView를 다시 초기화하려고했습니다. 그것도 작동하지 않았다.

+0

당신이 당신의 self.webView의 대리인으로 당신의 ViewController를 설정 한 프로토콜을 구현하는 것보다 추가해야합니까? –

+0

예, 웹보기가 작동 벌금을! 그냥 '내와 사용자 에이전트 헤더를 무시하지 않습니다 Desktop '값 – halilb

+0

onclick을 제대로 구현했는지 확인할 수 있습니까?보기 및 코드 간의 연결을 확인하십시오. – GoCrazy

답변

-1

에서 viewDidLoad는 대리인이어야합니다. (당신의 ViewController 헤더에서 당신은

- (void)viewDidLoad { 
[super viewDidLoad]; 

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"Desktop", @"UserAgent", nil]; 
[[NSUserDefaults standardUserDefaults] registerDefaults:dictionary]; 
// I miss this: 
self.webView.delegate = self; 
} 


@interface yourViewController : UIViewController <UIWebViewDelegate> 
+0

나는 이미 대리인을 지정 중이라고 말했고 webview는 이미 잘 작동하고 있습니다. useragent 헤더를 제외하고. – halilb

관련 문제