Estoy trabajando con un dispositivo móvil con escáner integrado. Para poder utilizar la biblioteca de JavaScript de diferentes dispositivos y evitar el conflicto con esas bibliotecas de diferentes fabricantes (Zebra, Honeywell, Datalogic, iOs ect ...) Necesito encontrar una manera de identificar cada dispositivo para que pueda cargar la biblioteca adecuada y esto es lo que se me ocurrió. Disfrutar de
getDeviceName: function() {
var deviceName = '';
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
Datalogic: function() {
return navigator.userAgent.match(/DL-AXIS/i);
},
Bluebird: function() {
return navigator.userAgent.match(/EF500/i);
},
Honeywell: function() {
return navigator.userAgent.match(/CT50/i);
},
Zebra: function() {
return navigator.userAgent.match(/TC70|TC55/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Datalogic() || isMobile.Bluebird() || isMobile.Honeywell() || isMobile.Zebra() || isMobile.BlackBerry() || isMobile.Android() || isMobile.iOS() || isMobile.Windows());
}
};
if (isMobile.Datalogic())
deviceName = 'Datalogic';
else if (isMobile.Bluebird())
deviceName = 'Bluebird';
else if (isMobile.Honeywell())
deviceName = 'Honeywell';
else if (isMobile.Zebra())
deviceName = 'Zebra';
else if (isMobile.BlackBerry())
deviceName = 'BlackBerry';
else if (isMobile.iOS())
deviceName = 'iOS';
else if ((deviceName == '') && (isMobile.Android()))
deviceName = 'Android';
else if ((deviceName == '') && (isMobile.Windows()))
deviceName = 'Windows';
if (deviceName != '') {
consoleLog('Devices information deviceName = ' + deviceName);
consoleLog('Devices information any = ' + isMobile.any());
consoleLog('navigator.userAgent = ' + navigator.userAgent);
}
return deviceName;
},
y esto es un ejemplo de cómo se puede utilizar:
initializeHandheldScanners: function() {
if (DeviceCtrl.getDeviceName() == 'Zebra')
DeviceCtrl.initializeSymbolScanner();
if (DeviceCtrl.getDeviceName() == 'Honeywell')
DeviceCtrl.initializeHoneywellScanner();
if (DeviceCtrl.getDeviceName() == 'Datalogic')
DeviceCtrl.initializeDatalogicScanner();
},
Se puede decir gracias a Cory Laviska. Hice esto basado en su trabajo. Aquí está el enlace si quieres saber más
https://www.abeautifulsite.net/detecting-mobile-devices-with-javascript
depende de qué navegador del dispositivo móvil se está ejecutando, pero qué quiere saber si es un iPhone o dispositivo Android o cuyo nombre es exactamente lo que necesita? –
Lo único que puede obtener es el User-Agent –
Aquí hay un enlace para usar 'WURFL.js', es gratis http://www.smashingmagazine.com/2014/07/01/server-side-device-detection- with-javascript/ – Pierre