So that mapping links open the maps app like they used to, I want to present a different link depending on whether a user is on iOS 6 or other (iOS 4, 5, Android, whatever).
映射链接像以前一样打开地图应用程序,我想根据用户是在iOS 6还是其他(iOS 4, 5, Android,等等)显示不同的链接。
Something like: -- if on iOS 6.0 or higher, show http://maps.apple.com?q="address", if other, show http://maps.google.com?q="address".
比如:——如果在iOS 6.0或更高版本上显示http://maps.apple.com?q=“address”,如果是“address”,则显示http://maps.google.com?q=“address”。
NOTE: I realize you can also call the maps app directly as opposed to via a web link (don't have it handy right now), but that would not fix the issue, since someone on Android or lesser iOS would get no use from that.
注意:我知道你也可以直接调用地图应用程序,而不是通过网络链接(现在还没有现成的),但这并不能解决问题,因为Android或iOS系统的某些人不会使用它。
5 个解决方案
#1
16
You can detect iOS version using the navigator.userAgent
string. Something like:
您可以使用navigator.userAgentstring检测iOS版本。喜欢的东西:
if(/(iPhone|iPad|iPod)\sOS\s6/.test(navigator.userAgent)) {
// use apple maps
}
Note that this is in no way future proof, user agent strings can change, and so will the OS. Also AFAIK, google maps via the browser is available on all platforms, including iOS 6.
注意,这绝不是未来的证明,用户代理字符串可以更改,操作系统也一样。此外,通过浏览器的谷歌地图也可以在所有平台上使用,包括iOS 6。
#2
5
Here's a bit of JS to determine iOS and Android OS version. No jQuery required.
下面是一些确定iOS和Android OS版本的JS。不需要jQuery。
Tested with actual user agent strings for iOS 4.3 to 6.0.1, and Android 2.3.4 to 4.2
iOS 4.3到6.0.1以及Android 2.3.4到4.2的实际用户代理字符串测试
var userOS; // will either be iOS, Android or unknown
var userOSver; // this is a string, use Number(userOSver) to convert
function getOS( )
{
var ua = navigator.userAgent;
var uaindex;
// determine OS
if ( ua.match(/iPad/i) || ua.match(/iPod/i) || ua.match(/iPhone/i) )
{
userOS = 'iOS';
uaindex = ua.indexOf( 'OS ' );
}
else if ( ua.match(/Android/i) )
{
userOS = 'Android';
uaindex = ua.indexOf( 'Android ' );
}
else
{
userOS = 'unknown';
}
// determine version
if ( userOS === 'iOS' && uaindex > -1 )
{
userOSver = ua.substr( uaindex + 3, 3 ).replace( '_', '.' );
}
else if ( userOS === 'Android' && uaindex > -1 )
{
userOSver = ua.substr( uaindex + 8, 3 );
}
else
{
userOSver = 'unknown';
}
}
Then to detect a specific version and higher, try:
然后检测特定版本和更高版本,尝试:
if ( userOS === 'iOS' && Number( userOSver.charAt(0) ) >= 5 ) { ... }
#3
2
You want to look into the user-agent string. The Safari web browser has a way of reporting what device (iPad, iPhone, etc) is being used and also the version number so its a matter of indexOf the information in that compact little string.
您需要查看用户代理字符串。Safari浏览器有一种方式来报告正在使用的设备(iPad、iPhone等),以及版本号,所以这是在那个紧凑的小字符串中信息的索引问题。
http://developer.apple.com/library/IOS/文档/ AppleApplications /引用/ SafariWebContent / OptimizingforSafarioniPhone OptimizingforSafarioniPhone.html # / / apple_ref / doc / uid / TP40006517-SW3
Some other helpful/very related * questions:
其他一些有用的/非常相关的*问题:
Detect iOS version less than 5 with JavaScript
使用JavaScript检测iOS版本小于5。
Detecting iOS Version on a Web Page
在网页上检测iOS版本
Check if iOS version is 3.0 or higher with PHP or Javascript
使用PHP或Javascript检查iOS版本是否为3.0或更高版本
#4
1
Use JavaScript to look at the user agent header.
使用JavaScript查看用户代理头部。
navigator.userAgent
#5
0
Using the user agent string is the right approach. If you're interested in getting the os version whether it's iOS, Android, or even Windows/Mac/BlackBerry, I wrote this detect-os-version component, that does exactly that. It also considers different versions user agents.
使用用户代理字符串是正确的方法。如果你对操作系统的版本有兴趣,不管是iOS, Android,甚至是Windows/Mac/黑莓,我都写了这个版本的版本组件,它确实做到了这一点。它还考虑不同版本的用户代理。
Feel free to import it and use as shown in these examples:
如下列例子所示,请随意导入和使用:
detectOsVersion.get() => {os: 'iOS', version: '5.1.1'}
detectOsVersion.get() => {os: 'BlackBerry', version: '7.1.0.346'}
detectOsVersion.get() => {os: 'Windows', version: '8.1'}
detectOsVersion.get() => {os: 'Android', version: '4.2.2'}
detectOsVersion.get() => {os: 'Mac', version: '10.7.1'}
#1
16
You can detect iOS version using the navigator.userAgent
string. Something like:
您可以使用navigator.userAgentstring检测iOS版本。喜欢的东西:
if(/(iPhone|iPad|iPod)\sOS\s6/.test(navigator.userAgent)) {
// use apple maps
}
Note that this is in no way future proof, user agent strings can change, and so will the OS. Also AFAIK, google maps via the browser is available on all platforms, including iOS 6.
注意,这绝不是未来的证明,用户代理字符串可以更改,操作系统也一样。此外,通过浏览器的谷歌地图也可以在所有平台上使用,包括iOS 6。
#2
5
Here's a bit of JS to determine iOS and Android OS version. No jQuery required.
下面是一些确定iOS和Android OS版本的JS。不需要jQuery。
Tested with actual user agent strings for iOS 4.3 to 6.0.1, and Android 2.3.4 to 4.2
iOS 4.3到6.0.1以及Android 2.3.4到4.2的实际用户代理字符串测试
var userOS; // will either be iOS, Android or unknown
var userOSver; // this is a string, use Number(userOSver) to convert
function getOS( )
{
var ua = navigator.userAgent;
var uaindex;
// determine OS
if ( ua.match(/iPad/i) || ua.match(/iPod/i) || ua.match(/iPhone/i) )
{
userOS = 'iOS';
uaindex = ua.indexOf( 'OS ' );
}
else if ( ua.match(/Android/i) )
{
userOS = 'Android';
uaindex = ua.indexOf( 'Android ' );
}
else
{
userOS = 'unknown';
}
// determine version
if ( userOS === 'iOS' && uaindex > -1 )
{
userOSver = ua.substr( uaindex + 3, 3 ).replace( '_', '.' );
}
else if ( userOS === 'Android' && uaindex > -1 )
{
userOSver = ua.substr( uaindex + 8, 3 );
}
else
{
userOSver = 'unknown';
}
}
Then to detect a specific version and higher, try:
然后检测特定版本和更高版本,尝试:
if ( userOS === 'iOS' && Number( userOSver.charAt(0) ) >= 5 ) { ... }
#3
2
You want to look into the user-agent string. The Safari web browser has a way of reporting what device (iPad, iPhone, etc) is being used and also the version number so its a matter of indexOf the information in that compact little string.
您需要查看用户代理字符串。Safari浏览器有一种方式来报告正在使用的设备(iPad、iPhone等),以及版本号,所以这是在那个紧凑的小字符串中信息的索引问题。
http://developer.apple.com/library/IOS/文档/ AppleApplications /引用/ SafariWebContent / OptimizingforSafarioniPhone OptimizingforSafarioniPhone.html # / / apple_ref / doc / uid / TP40006517-SW3
Some other helpful/very related * questions:
其他一些有用的/非常相关的*问题:
Detect iOS version less than 5 with JavaScript
使用JavaScript检测iOS版本小于5。
Detecting iOS Version on a Web Page
在网页上检测iOS版本
Check if iOS version is 3.0 or higher with PHP or Javascript
使用PHP或Javascript检查iOS版本是否为3.0或更高版本
#4
1
Use JavaScript to look at the user agent header.
使用JavaScript查看用户代理头部。
navigator.userAgent
#5
0
Using the user agent string is the right approach. If you're interested in getting the os version whether it's iOS, Android, or even Windows/Mac/BlackBerry, I wrote this detect-os-version component, that does exactly that. It also considers different versions user agents.
使用用户代理字符串是正确的方法。如果你对操作系统的版本有兴趣,不管是iOS, Android,甚至是Windows/Mac/黑莓,我都写了这个版本的版本组件,它确实做到了这一点。它还考虑不同版本的用户代理。
Feel free to import it and use as shown in these examples:
如下列例子所示,请随意导入和使用:
detectOsVersion.get() => {os: 'iOS', version: '5.1.1'}
detectOsVersion.get() => {os: 'BlackBerry', version: '7.1.0.346'}
detectOsVersion.get() => {os: 'Windows', version: '8.1'}
detectOsVersion.get() => {os: 'Android', version: '4.2.2'}
detectOsVersion.get() => {os: 'Mac', version: '10.7.1'}