Search code examples
iphonewebviewdetection

Having iPhone & iPad Perform Different Actions


I want the WebView to display a specific URL based on the device the user is using. For example:

if(deviceType == iPad)
{
     // Load Site on iPad & Retina iPad
     [webView loadRequest:[URLWithString:@"http://site.com/ipad.html"]];
}
else
{
    // Load Site on iPhone & Retina iPhone
    [webView loadRequest:[URLWithString:@"http://site.com/iphone.html"]];
}

How would I go about doing this? Thanks :)


Solution

  • Use something like:

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    

    UI_USER_INTERFACE_IDIOM() is a macro that calls the userInterfaceIdiom method of UIDevice, with a fallback if that method isn't available.