標籤:
#import <Foundation/Foundation.h>int main(int argc, char const *argv[]){ // 參考地址:http://ubluesky.com/archives/55 // NSURL初始化方法: NSURL *url=[NSURL URLWithString:@"http://www.ubluesky.com?id=1"]; // 針對 URLWithString 初始化失敗的解決方案 NSString *strLocalHtml = @"file:///Users/amarishuyi/Desktop/My IPhone Life/WebDeveloper/WebPlug-in/ExtEditor/DataPage/KMQT/Ext-HTMLEditor.html"; strLocalHtml = [NSString stringWithFormat:@"%@?Value=%@",strLocalHtml,self.txtUrl.text]; strLocalHtml = [strLocalHtml stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL * url=[NSURL URLWithString:strLocalHtml]; // 針對 fileURLWithPath 初始化失敗的解決方案 self.filePathString = [self.filePathString stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; NSURL *url = [NSURL fileURLWithPath:self.filePathString]; // NSURL 成功初始化後可以擷取的參數 NSURL *url = [NSURL URLWithString: @"http://www.baidu.com/s?tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709"]; NSLog(@"Scheme: %@", [url scheme]); NSLog(@"Host: %@", [url host]); NSLog(@"Port: %@", [url port]); NSLog(@"Path: %@", [url path]); NSLog(@"Relative path: %@", [url relativePath]); NSLog(@"Path components as array: %@", [url pathComponents]); NSLog(@"Parameter string: %@", [url parameterString]); NSLog(@"Query: %@", [url query]); NSLog(@"Fragment: %@", [url fragment]); NSLog(@"User: %@", [url user]); NSLog(@"Password: %@", [url password]); // 根據檔案名稱和檔案尾碼擷取程式包內容檔案的路徑 NSURL *urlKindEditor = [[NSBundlemainBundle]URLForResource:@"simple"withExtension:@"html"subdirectory:@"KindEditor/examples"]; // URLForResource:檔案名稱 // withExtension:檔案尾碼 // subdirectory:在程式包中的哪個子目錄中尋找. // 如果沒有找到將會返回nil // 找到後返回如下路徑: file://localhost/Users/amarishuyi/Library/Application%20Support/iPhone%20Simulator/5.1/Applications/FB0CDABC-D0E2-45FF-AA2C-959E8A65ADB4/SmallDemoList.app/KindEditor/examples/simple.html // 對比兩個URL 是否相等 [url isEqual:[_audioPlayer url]]; // 儘管iPhone不允許同時運行兩個應用程式,我們可以從自己的應用程式中啟動另一個應用程式,並且可以在應用程式之間共用資料。 // 我們可以使用UIApplication類的openURL:方法從一個應用程式來啟動另一個應用程式。 // 例如,要在Safari應用程式中開啟Google首頁,我們可以編寫如下代碼: NSURL *url = [NSURL URLWithString:@"http://google.com"]; [[UIApplication sharedApplication] openURL:url]; // 這裡的http://部分叫做URL方案(URL scheme),它表示想要載入的應用程式。 // 還有幾種用於本地iPhone應用程式的URL方案,並且可以使用類似的方式來啟動它們。 // 例如,要啟動Mail應用程式(3-15所示),我們可以使用: NSURL *url = [NSURL URLWithString:@”mailto:[email protected] subject= test”]; [[UIApplication sharedApplication] openURL:url]; // 要啟動SMS應用程式,我們可以編寫如下代碼: NSURL *url = [NSURL URLWithString: @"sms:555-1234"]; [[UIApplication sharedApplication] penURL:url]; // 要撥打一個電話號碼,我們可以使用如下代碼: NSURL *url=[NSURL URLWithString:@"tel://555-1234"]; [[UIApplication sharedApplication] openURL:url]; // 要啟動Maps應用程式來尋找一個披薩店(3-16所示),我們使用如下代碼: NSURL *url = [NSURL URLWithString:@"http://maps.google.com/maps?q=pizza"]; [[UIApplication sharedApplication] openURL:url]; // 我們也可以使用URL方案來啟動自己的應用程式: // 用一個定製的URL方案來啟動應用程式: // 1)建立一個新的基於視圖的應用程式,將其儲存為URLSchemeExample。 // 2)在Xcode Groups & Files面板中,展開Resource部分,並且選擇<app>-Info.plist檔案。 // 3)滑鼠右鍵點擊Information Property List鍵,並點擊添加箭頭從列表中選擇“URL types”(3-17所示)。 // 4)展開Item 1,用滑鼠右鍵點擊URL identifier,並且再次選擇添加箭頭從列表中選擇URL return 0;}
iOS開發中WebView的基本使用方法簡介