1)創建您的應用程序自定義URL方案。如果您不知道如何創建自定義URL方案,請點擊以下鏈接:http://www.idev101.com/code/Objective-C/custom_url_schemes.html
2)然後將以下腳本添加到您希望應用打開的URL。
<script language="javascript" type="text/javascript">
var iOS = (navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false);
var appUrlScheme = "myappscheme://" + document.URL;
if (iOS) {
window.open(appUrlScheme, "_self");
}
</script>
劇本是自我解釋,如果它的iOS設備,然後它只是試圖打開當前的URL與您的自定義URL方案即myappscheme://whateverurl.com'. If you app is installed on the device then iOS is going to launch your app and pass this URL to
handleOpenURL function, otherwise mobile safari will silently ignore
窗口。open`打電話,你的網頁將加載正常:
3)在你的AppDelegate實現handleOpenURL
回調方法來處理的網址:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
NSLog(@"url: %@", url);
NSLog(@"query string: %@", [url query]);
NSLog(@"host: %@", [url host]);
NSLog(@"url path: %@", [url path]);
//REDIRECT USER TO A VIEW CONTROLLER
return YES;
}
不,這是不可能沒有越獄。您可以讓您的網站嘗試重定向到您的自定義方案的URL,但... –
試試這個:A.讓你的應用程序處理html擴展。 B.用HTML文件(起始文件或重定向文件等)發送電子郵件鏈接 – user523234
@SimonM我認爲你是唯一的解決方案。要使用常規鏈接(http://something.com/product/3/)並在該網頁中嘗試打開帶有myscheme://something.com/product/3/的彈出窗口,該窗口將打開該應用(如果已安裝)或顯示一些東西(可能會顯示谷歌搜索,因爲它不理解myscheme作爲網址)。 – jobima