通过设置 UserAgent 让服务器识别 app

通过设置 UserAgent 让服务器识别 app信息

- (void) resetUserAgent {

    
    // Do any additional setup after loading the view, typically from a nib.
    UIWebView *webView = [[[UIWebView alloc] initWithFrame:CGRectZero] autorelease];
    NSString *Agent = [webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
    
    
    //add my info to the new agent
    NSString *newAgent = nil;

    newAgent = [Agent stringByAppendingString:@" myMobileApp"];
    
    //regist the new agent
    NSDictionary *dictionnary = [[NSDictionary alloc] initWithObjectsAndKeys:newAgent, @"UserAgent",nil];
    [[NSUserDefaults standardUserDefaults] registerDefaults:dictionnary];


}


转载于:https://www.cnblogs.com/skyry/p/5114502.html

你可能感兴趣的:(通过设置 UserAgent 让服务器识别 app)