Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-Agent Not Updating in NSUserDefaults / WKWebView #63

Open
hsnbsst opened this issue Feb 20, 2025 · 0 comments
Open

User-Agent Not Updating in NSUserDefaults / WKWebView #63

hsnbsst opened this issue Feb 20, 2025 · 0 comments

Comments

@hsnbsst
Copy link

hsnbsst commented Feb 20, 2025

Description:
I’m trying to update the User-Agent in my iOS/macOS app, but it doesn’t seem to take effect. Even after setting the new value in NSUserDefaults, the web requests still use the old User-Agent.

Steps to Reproduce:
Set a new User-Agent in NSUserDefaults:

[[NSUserDefaults standardUserDefaults] setObject:@"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36 Edg/132.0.0.0"  
                                          forKey:@"UserAgent"];  
[[NSUserDefaults standardUserDefaults] synchronize];  

Expected Behavior:
The User-Agent should update immediately after restarting the app.
WKWebView and network requests should use the new User-Agent.
Actual Behavior:
The User-Agent remains the same as before.
The system does not seem to apply the changes.
Additional Notes:
I tried using registerDefaults: and setObject: but neither worked.
Restarting the app did not help.
Clearing cache with [[NSURLCache sharedURLCache] removeAllCachedResponses]; had no effect.
WKWebView.customUserAgent also does not seem to change the actual requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant