有时候你的程序需要知道用户使用的设备是iPhone还是iPod。因为有些特性iPod是没有的,比如电话功能。方法很简单:
NSString *deviceType = [UIDevice currentDevice].model;
如果你想得到一个本地化的字符串,可以使用以下命令:
NSString *deviceType = [UIDevice currentDevice].localizedModel;
NSLog(@”type: %@”, deviceType);
JavaScrpit代码:
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
if (document.cookie.indexOf(“iphone_redirect=false”) == -1) {
window.location = “http://m.espn.go.com/wireless/?iphone&i=COMR”;
}
}
代码很简短,和pc端判断浏览器一样采用navigator.userAgent来判断。不过我觉得这种场景用程序判断更适合,带来的未知bug会相对少一些。我只略懂一点php,下面就用php来实现这个效果吧:
PHP代码:
if(strstr($_SERVER['HTTP_USER_AGENT'],’iPhone’) || strstr($_SERVER['HTTP_USER_AGENT'],’iPod’))
{
header(‘Location: http://yoursite.com/iphone’);
exit();
}