Change User Agent in UIWebView

前端 未结 14 1996
孤城傲影
孤城傲影 2020-11-22 17:03

I have a business need to be able to customize the UserAgent for an embedded UIWebView. (For instance, I\'d like the server to respond differently if, say, a user is using

14条回答
  •  礼貌的吻别
    2020-11-22 17:53

    Try this in the AppDelegate.m

    + (void)initialize 
    
    {
    
        // Set user agent (the only problem is that we can’t modify the User-Agent later in the program)
    
        // iOS 5.1
    
        NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:@”Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9B176 Safari/7534.48.3”, @”UserAgent”, nil];
    
    
        [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];
    
    }
    

提交回复
热议问题