0

I'd like to be able to tell the difference between a user hitting my website on normal Safari as included in iphone or ipad, VS a user who is hitting the same content through a UIWebView within a native iOS app.

I was hoping there'd be a way with javascript and user-agent strings? Any point in the right direction for further investigation would be greatly appreciated!

thanks!

korben
  • 537
  • 1
  • 7
  • 18
  • I don't know whats possible with JS but user-agents strings can be manipulated... – HAS Apr 25 '13 at 14:58
  • 2
    http://stackoverflow.com/questions/2143763/does-uiwebview-send-the-same-user-agent-in-the-request-headers-as-mobile-safari – Emmanuel Apr 25 '13 at 15:06
  • 1
    thanks that's definitely helpful, I wish there was something a bit more "official" in-case the word "safari" ever starts showing up in the user-agent, but I guess it'll have to do for now – korben Apr 25 '13 at 15:46

1 Answers1

0

I would suggest you send a GET variable in your URL string in the native iOS App and save that value to a session variable on your webserver. Then use the session variable to do things different for Mobile Safari and the UIWebview

In your iOS App when you request your site add the Get Variable

iOS

NSString *urlQueryString = @"?BrowserType=iOSNative";
NSString *URLPath = [NSString stringWithFormat:@"http://www.yoursite.com/%@",urlQueryString ];
NSURL *requestURL = [NSURL URLWithString:URLPath];
NSURLRequest *request = [NSURLRequest requestWithURL:requestURL];
[self.webview loadRequest:request];

PHP

if(isset($_REQUEST['BrowserType']))
{
    //Used for tracking is this is an iOS Native App user.   
    //This will not be set by the mobile browser user
    $browserType = filter_var($_REQUEST['BrowserType'], FILTER_SANITIZE_STRING);
    $_SESSION['BrowserType']=$browserType;
}
if ($_SESSION['BrowserType']=="iOSNative")
{
    echo 'This is the native App and shouldn't display on the mobile page';
}
PHPDave
  • 904
  • 1
  • 7
  • 15