totpero / DeviceDetector.NET

The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.
Apache License 2.0
348 stars 73 forks source link

iPhone IOS version not detected #70

Closed rogerfar closed 10 months ago

rogerfar commented 1 year ago

I am trying to parse this user agent: Mozilla/5.0+(iPhone;+CPU+iPhone+OS+13_4+like+Mac+OS+X)+AppleWebKit/605.1.15+(KHTML,+like+Gecko)+CriOS/77.0.3865.103+Mobile/15E148+Safari/605.1

When I use the PHP version: image https://devicedetector.lw1.at/Mozilla%2F5.0+(iPhone;+CPU+iPhone+OS+13_4+like+Mac+OS+X)+AppleWebKit%2F605.1.15+(KHTML,+like+Gecko)+CriOS%2F77.0.3865.103+Mobile%2F15E148+Safari%2F605.1

But when using C# latest version: image https://dotnetfiddle.net/LIV2yB

totpero commented 10 months ago

Hi @rogerfar,

Your problem is because your User Agent string contains + instead of space character. If you replace the + with space like this: Mozilla/5.0 (iPhone; CPU iPhone OS 13_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/77.0.3865.103 Mobile/15E148 Safari/605.1 the result will be the same: image The + character is user to encode space from URL on https://devicedetector.lw1.at

If you will use this library in .net project, this will not happen because the request UserAgent will be ok. If your UserAgent string comes from other source ..you will need to manipulate this string before send this to Device Detector 👍