2013-04-25 64 views
0

我希望能夠分辨出用戶在iphone或ipad中包含的正常Safari上的我的網站,VS通過UIWebView在本機iOS應用中擊中相同內容的用戶。我可以在移動Safari(iphone)VS UIWebView(WebKit)用javascript檢測用戶嗎?

我希望有一種方式與JavaScript和用戶代理字符串?任何進一步調查的正確方向都將不勝感激!

謝謝!

+0

我不知道JS有什麼可能,但用戶代理字符串可以是ma nipulated ... – HAS 2013-04-25 14:58:17

+2

http://stackoverflow.com/questions/2143763/does-uiwebview-send-the-same-user-agent-in-the-request-headers-as-mobile-safari – Emmanuel 2013-04-25 15:06:20

+1

謝謝,這絕對有幫助,我希望有更多的「官方」,以防萬一「safari」這個詞開始出現在用戶代理中,但我想現在它必須要做 – korben 2013-04-25 15:46:54

回答

0

我建議你在本地iOS應用程序的URL字符串中發送GET變量,並將該值保存到Web服務器上的會話變量。然後使用會話變量做的事情不同的移動版Safari和UIWebView的

在iOS應用,當你申請你的網站添加獲取變量

的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'; 
} 
相關問題